How to recover an unsaved "untitled2.m" script after computer crashed

392 views (last 30 days)
I have been working in an unsaved "untitled2.m" script when my computer crashed.
When restarting matlab this unsaved document was gone along with the .asv files in my current directory.
However, when opening a new script I noticed that the new scripts filename is "untitled3.m", which means that somewhere the "untitled2.m" document must exist. The question is where? I assume this is some temporary folder created somewhere while matlab is still running. But how do I access this folder/file using Macbook.

Answers (3)

Codey Nacke
Codey Nacke on 2 Sep 2024
I had a similar issue and was able to recover the code. I had an untitled file that I was working on and hadn't yet saved when my power went out. I was able to find the script in the temp folder.
First, navigate to where Matlab is storing temp files by running tempdir then navigating to that folder in your file system.
Next, I found a folder called "Editor_wtfiy" that had a file called "LiveEditorEvaluationHelperE1112034879.m" that had a copy of my code. I assume that the "E1112034879" is a unique identifier for each script.
TLDR: Look in ~tempdir~/Editor_wtfiy/LiveEditorEvaluationHelper[...].m

Walter Roberson
Walter Roberson on 2 Mar 2023
Look in the location indicated by the command tempdir .
However, in practice that directory is used for MATLAB mostly to store files being built into a .slx or .xlsx, or code extracts when running LiveScript or running regular script section by section ("Run and Advance")
You could also look under ~/Library/'Application Support'/MathWorks/MATLAB but I don't think you will find anything useful there.
Time to invoke Time Machine.
  2 Comments
Marie Bergelin
Marie Bergelin on 3 Mar 2023
Thank you!
I did look in the 'tempdir' folder, but I can find the content anywhere.
I was able to find the files that logs past commands in the command window in the '~/Library/'Application Support'/MathWorks/MATLAB' path. But only part of my code exist there.
The fact the the script number in the name increases every time I generate a new script, must mean that a file named "untitled2.m" exist.
Walter Roberson
Walter Roberson on 3 Mar 2023
The file name might hypothetically be handled by something recorded in prefdir .
I just tested on my system, creating some untitled files and deleting them all. The next file had the next sequence number. (At least within the same session; I did not test closing MATLAB.)

Sign in to comment.


Praprara
Praprara on 16 Sep 2024
Lol I came to this page 2 months ago for this same issue but since you hadn't commented, I wasn't been able to get back the file. But seeing this comment now, I finally know how to retrieve 'lost' matlab files. Thank you!

Categories

Find more on Entering Commands 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!