Can I make a function for several sets of input

1 次查看(过去 30 天)
I want to make my scripts faster, so Im replacing for loops with functions.
However the segment below gets bigger as one script is dealing with 2 vehicles(script H2) and one other with 3 (script H3).
Vehicle is the vehicles charging profile over one year, ID is the ID number of the vehicle. INCREASE2 is how much the household maximum power demand will increase.
Segment in H2:
for jj=1:numel(VID1)
V11=Vehicle1{jj};
ID1=VID1{jj};
for jj2=1:numel(VID2)
V22=Vehicle2{jj2};
ID2=VID2{jj2};
%Removes all doubles
if numel(intersect(ID1,ID2))
continue
end
INCREASE2{jj,jj2}=max(HH2+V11+V22)./max(HH2);
end
end
Segment in H3
for jj3=1:numel(VID3)
V3=Vehicle3{jj3};
ID3=VID3{jj3};
for jj=1:numel(VID1)
V1=Vehicle1{jj};
ID1=VID1{jj};
if numel(intersect(ID1,ID3))
continue
end
for jj2=1:numel(VID2)
V2=Vehicle2{jj2};
ID2=VID2{jj2};
%Removes all doubles
if numel(intersect(ID1,ID2))
continue
end
INCREASE2{jj,jj2}=max(HH2+V1+V3+V2)./max(HH2);
end
end
end
So I would like to create a function that replaces these for loops. But since there will be more for loops in some cases Im not sure how

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by