Combining columns of two matrices

1 view (last 30 days)
Joel Schelander
Joel Schelander on 18 Mar 2021
Commented: Joel Schelander on 19 Mar 2021
I have 8 Battery electric vehicles and 16 apartments.
The 8 Battery electric vehicles are stored in a 525600*8 matrix (A)
The 16 apartments are gathered in one matrix (525600x16) (Appartment),.
Both are describing a power demand.
I want to combine these, i.e. Add up the power demands. This is how far I got, but I dont know how I do for all combinations.
x = randi(size(Appartment,2));
App = Appartment(:,x);
y = randi(size(A,2));
Vehicle = A(:,y);
P=App(:,1)+Vehicle(:,1)';
I=max(P)/max(App(:,1));
I is how much the max power demand increases when a Battery electric vehicle is introduced.
I want to save the I values for all combinations for later use

Accepted Answer

Jan
Jan on 18 Mar 2021
Edited: Jan on 18 Mar 2021
If you want to find all combinations of 2 values, simply use two loops:
for x = 1:size(Appartment, 2)
App = Appartment(:,x);
for y = 1:size(A, 2)
Vehicle = A(:,y);
P = App(:,1) + Vehicle(:,1)';
I = max(P) / max(App(:,1));
end
end
I guess, you want to store the valuzes of I? Then you need something like I(x,y) = ... .
There are faster versions without loops also. But lets clarify at first, if this is, what you are searching for.
  7 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!