MATLAB not able to make calculation - array limit
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Joel Schelander
am 22 Mär. 2021
Kommentiert: Joel Schelander
am 22 Mär. 2021
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 Kommentare
DGM
am 22 Mär. 2021
Yeah, that rand() was me just adding a dummy variable into the example when I was testing it
Akzeptierte Antwort
Steven Lord
am 22 Mär. 2021
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)
B = randi(1000, 1, 10)
D = A.'+B; % Makes a relatively big temporary
C1 = max(D, [], 'all')
C2 = max(A)+max(B)
whos A B C1 C2 D
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 Kommentare
Steven Lord
am 22 Mär. 2021
rng(1, 'twister')
vehicle = 11*randi([0 1], 1, 10)
apartment = randi(10, 1, 10)
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
Or do you want it to be the 18 in the second column of vectorOfCombinationsAtTheSameTime?
vectorOfCombinationsAtTheSameTime = vehicle+apartment
Your code is as written tries using matrixOfAllCombinations, though because that matrix is really large MATLAB stops you from creating it.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spline Postprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!