Error using zeros and out of memory
Show older comments
Hi everyone, a friend of mine helped me write this code. The code works but, if I increase the values on lines 11, 12 and 13, I get this error message:
Error using zeros Requested 624x103x103x300 (14.8GB) 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.
Can you help me solve this problem? The processing of all the code really takes a very long time, I think it can certainly be written better by reducing processing time but I do not know how to do it.
Thank you.
33 Comments
jonas
on 8 Nov 2018
The error message is very clear, I don't know what else to say to be honest. You try create an array with 2 billion elements, which is too much to store in memory.
Stephen23
on 8 Nov 2018
"Can you help me solve this problem?"
You have three main choices:
- buy more memory, or
- process less data, or
- change your algorithm.
Which do you want to do?
Marco Tavecchia
on 8 Nov 2018
Rik
on 8 Nov 2018
Have you tried using the profiler to find out where the bottleneck is for your function? Your code is quite lengthy and since the comments are in Italian(?) I don't understand them enough to understand your algorithm and propose a solution.
Marco Tavecchia
on 8 Nov 2018
Edited: Marco Tavecchia
on 8 Nov 2018
Rik
on 8 Nov 2018
@Jan, be happy that the code was included as an attachment, otherwise you'd spend quite some time scrolling...
@Marco, those calls to xlsread are not repeated, so those can only be sped up by not storing the data in excel files, but store them in a mat file instead (checking every time if the mat file is newer to make sure no edits to the excel file are missed).
Marco Tavecchia
on 8 Nov 2018
Marco Tavecchia
on 9 Nov 2018
Edited: Marco Tavecchia
on 9 Nov 2018
Walter Roberson
on 9 Nov 2018
save('49giorni5day.mat','AllData')
Marco, I don't think you should focus on the way you store your inputs/outputs for now. Yes, using excel is not particularly efficient but it's a minor problem compared to the big one:
Your current processing algorithm (which I've not tried to understand) requires the creation and processing of lots of very large 4D matrices. In the beginning of your code I counted the creation at least 24 matrices of size 624x103x103x300 (If your comment is correct about the sizes) which is going to require around 355 GB of memory alone.
You need a fundamental change of algorithm, not minor edits here and there. You need to come up with an algorithm that doesn't require storing/generating so much data. Or you need to run your algorithm on a supercomputer, standard desktop computers simply won't cut it for that.
Marco Tavecchia
on 9 Nov 2018
Edited: Marco Tavecchia
on 9 Nov 2018
Marco Tavecchia
on 9 Nov 2018
Edited: Marco Tavecchia
on 9 Nov 2018
"if you have any suggestions I try to start editing something"
Guillaume already explained what you need to do:
"You need a fundamental change of algorithm, not minor edits here and there"
Walter Roberson
on 9 Nov 2018
I would like a file with 5617 rows and 9 columns.
However that is the size of your txt by itself. Where would num be put?
Marco Tavecchia
on 9 Nov 2018
Edited: Marco Tavecchia
on 9 Nov 2018
Walter Roberson
on 9 Nov 2018
AllData = raw(:,1:9);
Marco Tavecchia
on 12 Nov 2018
Edited: Marco Tavecchia
on 12 Nov 2018
Rik
on 12 Nov 2018
The load function loads the variables inside the file to a struct, so you still need to parse that:
input_mat = load('input_mat2.mat'); AllData=input_mat.AllData;
alfa = round(AllData(6,2))
Marco Tavecchia
on 12 Nov 2018
Edited: Marco Tavecchia
on 12 Nov 2018
Marco Tavecchia
on 12 Nov 2018
Guillaume
on 12 Nov 2018
Marco, in your original comment you said: "I'm trying to rewrite the code from the beginning"
Yes, you should do that. However, as I said originally, you should not worry about how you get your data into matlab for now. That's a minor detail at this point. What you need to fundamentally change is what you do with that data once it's loaded. You cannot use it to generate over 350 GB of matrices. Even one matrix of 15 GB is most likely to tax your computer and be slow to process.
Once you have a processing algorithm that doesn't require so much data, then you can focus on speeding up the import, if it's still an issue.
Marco Tavecchia
on 12 Nov 2018
Marco Tavecchia
on 12 Nov 2018
Edited: Marco Tavecchia
on 12 Nov 2018
Marco Tavecchia
on 12 Nov 2018
Edited: Marco Tavecchia
on 12 Nov 2018
Walter Roberson
on 12 Nov 2018
Estremo_Superiore_Variazione_Percentuale = AllData{11,2};
And similar changes. The raw output of xlsread is a cell array.
Marco Tavecchia
on 13 Nov 2018
Edited: Marco Tavecchia
on 13 Nov 2018
Marco Tavecchia
on 13 Nov 2018
Marco Tavecchia
on 13 Nov 2018
Rik
on 13 Nov 2018
It looks like your values are stored in cells, so they are not numeric, hence the error.
As Rick says, somehow you've managed to store your gamma,delta, etc. in cell arrays. What's clear though is that their value has not changed and you still requires massive amounts of memory.
This is the last time I'm saying this: You need a fundamental change of algorithm. You need to throw away your current code and start fresh with a completely new way of processing your data. Changing your current code one line at a time is not going to work.
In my opinion, you would be better off starting a new question explaining what your inputs are and what you want to calculate from them and let us come up with an algorithm.
Marco Tavecchia
on 13 Nov 2018
@Marco Tavecchia: and please format your comments properly. Formatting the entire comment text with monospaced typeface does not make your comments easy to read and follow. Learn to use that nice toolbar above the textbox: do you notice it has a section for formatting code?
Today I formatted your last few comments for you. In future you can do it yourself.
Marco Tavecchia
on 13 Nov 2018
Answers (0)
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!