MATLAB not able to make calculation - array limit

I want to find the new max electricity consumption of an appartment when an EV is introduced.
Appartment is the load profile for 16 appartments (one value each minute for one year)
A is the load profile from charging for 2 vehicles.
I use this
nHousehold =size(Appartment, 2);
Appartment=525600*16 double
A=525600*2 double
for x = 1:nHousehold
App = Appartment(:, x);
for y = 1:nA
Vehicle = A(:, y);
I(x,y) = max(Vehicle.'+App)./max(App);
end
end
I get this error:
Requested 525600x525600 (2058.3GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become
unresponsive. See array size limit or preference panel for more information.
Error in RELATION (line 41)
I(x,y) = max(Vehicle.'+App)./max(App);
The output I should be a 16*2 matrix, so I wonder if I somehow can circumvent this error?

7 Comments

I don't know how you're getting an error, since this code isn't going to run at all.
You're referencing a variable before it's defined.
nHousehold =size(Appartment, 2);
These lines are going to throw an error. I'm going to assume that this is pseudocode for the sake of this example. Maybe this is defined before the prior line?
Appartment=525600*16 double
A=525600*2 double
The inner loop iteration vector references a variable that doesn't exist:
for y = 1:nA
I don't know why you're taking the elementwise transpose of a column vector and then trying to add it to another column vector. That's not going to work.
I(x,y) = max(Vehicle.'+App)./max(App);
I'm just guessing, but is this what you're trying to do?
Household=rand([525600 16]);
EVprofile=rand([525600 2]);
nH=size(Household, 2);
nEV=size(EVprofile, 2);
I=zeros([16 2]);
for x = 1:nH
thishousehold = Household(:, x);
for y = 1:nEV
thisevp = EVprofile(:, y);
I(x,y) = max(thisevp+thishousehold)./max(thishousehold);
end
end
@DGM: "I don't know why you're taking the elementwise transpose of a column vector and then trying to add it to another column vector. That's not going to work."
This is working since Matlab R2016b and called "auto-expanding" (or similar names):
(1:3).' + (4:5)
ans =
5 6
6 7
7 8
This was done by bsxfun in former Matlab versions.
The only problem is, that the vectors are to large to fit into the memory. But even with using a loop this would be very slow, because it would compare 276e6 values in each loop.
@Joel Schelander: Are Appartment and A filled with non-zero values? Would rand(525600, 16) be a real world data set? Or do the data have a specific structure?
Do you want to find the maxium of the sum of the two vectors? Or dou you want to find out, which combination of all elements of the vectors are maximal?
Having a tiny input data set and the wanted output would clarify this immediately.
Oh. I didn't know that. I'm on R2015b.
Both contain nonzero values.
A denotes what minute the charging occur, so if there is a charging event occuring, that row contains the value 11, else it is zero
Appartment only contains non-zero values. This stands for the electricity load of the appartments and has been extracted from an excel file, so rand(525600, 16) is not in my code. By structure do you mean the nr of rows and columns? That is stated at the top.
Yeah, that rand() was me just adding a dummy variable into the example when I was testing it
@Jan the vectors are added, so each minute will have a new electricity consumption, where charging is included
The maximum of the two added to each other. like:
P=max(App+Vehicle)
I=P/max(App)
The output I should in this case be a 16*2 matrix, expressing the increase in the max value for all combinations

Sign in to comment.

 Accepted Answer

The maximum of the sum of an element from A and an element from B (which is what I think you want, not what you're doing) is the sum of the maximum element in A and the maximum element in B.
A = randi(1000, 1, 10)
A = 1×10
940 288 123 144 841 568 480 564 263 905
B = randi(1000, 1, 10)
B = 1×10
827 892 706 954 88 247 82 9 567 334
D = A.'+B; % Makes a relatively big temporary
C1 = max(D, [], 'all')
C1 = 1894
C2 = max(A)+max(B)
C2 = 1894
whos A B C1 C2 D
Name Size Bytes Class Attributes A 1x10 80 double B 1x10 80 double C1 1x1 8 double C2 1x1 8 double D 10x10 800 double
So I think you could simplify this code a bit so it doesn't make such a huge temporary array.
%{
nHousehold =size(Appartment, 2);
Appartment=525600*16 double
A=525600*2 double
for x = 1:nHousehold
App = Appartment(:, x);
maxApp = max(App);
for y = 1:nA
Vehicle = A(:, y);
I(x,y) = max(Vehicle)+maxApp./maxApp;
end
end
%}
You could likely avoid the inner loop by calling max with a dim input.

3 Comments

This is not what I want as this does not take into account how the load profiles look.
Vehicle only consists of 11 or 0 (the charger has a charging rate of 11 kW). So max(Vehicle) would be fixed.
As charging events occur at different times and do not always coincid with max(App) I cannot do this.
I(x,y)=max(Vehicle+App)/max(App) is how much the maximum load increase, if a specific vehicle is deployed to a specific apartment.
rng(1, 'twister')
vehicle = 11*randi([0 1], 1, 10)
vehicle = 1×10
0 11 0 0 0 0 0 0 0 11
apartment = randi(10, 1, 10)
apartment = 1×10
5 7 3 9 1 7 5 6 2 2
For these specific vectors, what do you want to be used in the calculation of your array and why? Do you want the answer to be one of the 20's in the fourth column of matrixOfAllCombinations?
matrixOfAllCombinations = vehicle.'+apartment
matrixOfAllCombinations = 10×10
5 7 3 9 1 7 5 6 2 2 16 18 14 20 12 18 16 17 13 13 5 7 3 9 1 7 5 6 2 2 5 7 3 9 1 7 5 6 2 2 5 7 3 9 1 7 5 6 2 2 5 7 3 9 1 7 5 6 2 2 5 7 3 9 1 7 5 6 2 2 5 7 3 9 1 7 5 6 2 2 5 7 3 9 1 7 5 6 2 2 16 18 14 20 12 18 16 17 13 13
Or do you want it to be the 18 in the second column of vectorOfCombinationsAtTheSameTime?
vectorOfCombinationsAtTheSameTime = vehicle+apartment
vectorOfCombinationsAtTheSameTime = 1×10
5 18 3 9 1 7 5 6 2 13
Your code is as written tries using matrixOfAllCombinations, though because that matrix is really large MATLAB stops you from creating it.
I dont want a matrix, but I tried
I=max(App+Vehicle)./max(App) and got the result I wanted

Sign in to comment.

More Answers (0)

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!