Storing a Finite Difference History
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Is there a good way to store finite difference history. I initially tried getframe() but that required that the frame actually pop up, which prohibited me from using the computer while the simulation was running. I next turned to making a 3 dimensional matrix but this requires a ton of memory, even if I store the values as singles rather than doubles. It's been pretty tedious to recalculate how much memory I'll be using every time I change a parameter on the simulation. Last time I ran it, it ran 8 hours before erroring out with a memory error. I don't really even understand why because I pre declared my history variable: basically
Hist = zeros(251,251,400);
which took fine, but then errored hours into the program when saving a time frame e.g.:
Hist(:,:,I) = NewMap;
where I is still less than 400;
So I've kind of got a problem and a half here. I have a memory problem that I'd like to find a new way around altogether, but I'd also like to understand why I'm getting this memory error to begin with.
Thanks, Jason
5 Comments
Sean de Wolski
on 31 Oct 2011
Could you show a little bit more of the code please.
(251*251*400)elements * 4 bytes/element (single)
should not be cause memory errors on most modern systems.
Jason Smoker
on 31 Oct 2011
Image Analyst
on 6 Nov 2011
Why are you "saving" the zeros array to the exact same variable called "Hist" again? That's bad practice, by the way, to use a built-in function name as the name of your variable even if MATLAB is case sensitive.
Image Analyst
on 6 Nov 2011
Try clearvars instead of clear all.
Jason Smoker
on 8 Nov 2011
Answers (1)
Dr. Seis
on 31 Oct 2011
0 votes
It may be more time consuming, but if you could code something up to simply write out the results to a text file (or binary file) then you at least have a copy of what was done and all would not be lost. You could even set it up to pick up where it left off if for some reason the run bombs (and you still think the prior results in the history are valid).
5 Comments
Jason Smoker
on 31 Oct 2011
Dr. Seis
on 2 Nov 2011
I don't understand why you need 400+ variables. In order to compute the current state you should only need the last state. So you should have only 2 matrices (i.e., "a" and "a_old"). "a_old" would be the initial state before you begin, then "a" would be computed based on "a_old". For the next loop, "a" would become "a_old" and the process would repeat... except after each loop you write out "a".
Jason Smoker
on 6 Nov 2011
Dr. Seis
on 7 Nov 2011
There are other ways to write out a matrix to a txt file in a way that you can append the next, say, 4x4 matrix to the the bottom of the file. For example, each line you print out to the file could be the 16 elements of your matrix. Afterwards, you can visualize that data by pulling out a sub-set of rows and reconstruct to the original 4x4 matrix.
If you want to use something like "getframe" but without a figure/frame popping up, then check out "im2frame" in the help navigation window. If you can figure out how to make an indexed image, then you can basically save each frame without having those pesky figure/frames pop up.
Jason Smoker
on 8 Nov 2011
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!