Combining matrices without for loops

2 views (last 30 days)
Joel Schelander
Joel Schelander on 12 Apr 2021
Commented: Walter Roberson on 15 Apr 2021
I have two houses, House 1 and house 2. Each house has one or two Electric Vehicles(EV), each EV has its own specific ID number. I want to find how much more max power House 1 and House 2 are jointly demanding when EVs are introduced. So far I have used for loops like this:
Vehicle1{jj}, Vehicle2{jj2} and HH2 are of the size 525600x1 double: the power demand every minute of the year
In this example there are 3 available vehicles, so the Vehicle and VID cells will both have the size 3x3
%Vehicle1 - electricity consumption of House 1s vehicle(s)
%Vehicle2- electricity consumption of House 1s vehicle(s)
%VID1 - ID number of vehicle(s) for House 1
%VID2 - ID number of vehicle(s) for House 2.
%HH2
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 (House 1 and House 2 cannot have the same car)
if numel(intersect(ID1,ID2))
continue
end
INCREASE2{jj,jj2}=max(HH2+V11+V22)./max(HH2);
%IDcell2{jj,jj2}=[ID1 ID2];
end
end
Since there are many vehicles to consider and more houses to combine, I need to find another way to perform this calculation.
Is there some other way?

Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!