Recovering workspace after exiting Matlab

104 views (last 30 days)
Hi guys,
I have made a big mistake by not including a command to save my workspace after my simulation ends. My computer shut down and now I don't have most of the matrices from my simulation results. Is it possible at all to recover my workspace after I exited Matlab without saving them? I've googled this and everybody says it's impossible. Just in case anybody has a different answer.
cheers,
Febrio

Accepted Answer

Walter Roberson
Walter Roberson on 14 Dec 2011
The data is gone. MATLAB keeps workspace contents in memory and does not bother to write the contents to disc unless it is asked to.

More Answers (1)

Michael Melnychuk
Michael Melnychuk on 26 Jan 2015
I think the core dev's should consider adding an autosave/recover function.
  3 Comments
Stephen23
Stephen23 on 2 Feb 2016
Edited: Stephen23 on 2 Feb 2016
Just imagine the complaints:
"MATLAB auto-saved three Tebibytes of data onto my harddrive..."
"I relied on MATLAB to auto-save my data, but I don't have enough diskspace and it missed some of my data. How do I get this missing data?"
"MATLAB is sooooo sloooow... " (while MATLAB tries in the background to save fifty Gibibytes of data).
"I reverted my workspace to the saved version... but now I changed my mind. How do I get my first workspace back?"
The only complete solution would be to back up every code step and every variable at every change. This works great if you have infinite disk-space and infinite computing power.
A more robust solution is to:
  • Stop writing scripts and learn to write functions.
  • Stop relying on the base workspace. This workspace is for playing around, not for serious work. Use functions!!!
  • Keep track of data and save it when possible. This is easy with functions, as processing can be re-started from the last saved data.
  • Avoid amateur commands like clear all. Have a good look at well-written code on MATLAB File Exchange: none of them use clear all. In fact most of them are functions, not scripts. The reason: to encapsulate their functionality and workspace (in other words: to manage their data properly, so that it is not in the base workspace, so that other people cannot mess it up).
  • Oh, and learn to use functions instead of scripts.
Emir Semsic
Emir Semsic on 6 Feb 2019
So you're saying we should use functions instead of scripts?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!