How can I restore a previous version of an m-file that I have accidentally overwritten with a MAT-file ?

조회 수: 395 (최근 30일)
How can I restore a previous version of an m-file that I have accidentally overwritten with a MAT-file (I guess with the command "save") ?
Now it it is unreadable and with stange symbols, and it looks like this:
MATLAB 5.0 MAT-file, Platform: MACI64, Created on: Fri Aug 30 19:21:09 2019
  댓글 수: 3
Image Analyst
Image Analyst 2019년 9월 12일
The Mathworks makes it possible to do version control using the version control of your choice, like Tortoise Subversion. (Personally I don't do it from within MATLAB -- I do it outside MATLAB via File Explorer.)
Charles D'Onofrio
Charles D'Onofrio 2024년 4월 28일 15:03
I also had this issue recently. It occured because I meant to save two variables using:
save('greedyResults',"greedyMatrix","greedyTable");
But I must have mistakenly hit the tab button with caused the MATLAB autocomplete to type:
save('greedyNodes',"greedyMatrix","greedyTable");
greedyNodes was the name of my function that was overwritten. This is clearly user error but it would be great if MATHWORKS could disable the autocomplete ability to write .m files into the save command. The risk of overwritting days' worth of work is not worth the 2 second time savings of autocomplete on the save command.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 8월 31일
Unless you happen to have an autosave file (.asv or .m~ ) then there is no MATLAB way to restore the file after you have closed the file in the editor.
If you have no yet closed the file in the editor, then you just might be able to ^Z in the editor to restore the previous version, but I would not count on it.
The long term way to deal with this situation is to ensure that your system has regular backups taken, or else to deliberately make copies of the file from time to time as you work on it. You should also be considering using a version control system.
  댓글 수: 1
Sim
Sim 2019년 8월 31일
Thanks @Walter Roberson... By your answer I can deduce there is nothing else I can do, but to re-write the entire code....... I will follow your kind advices... Actually... I was exactly trying to save the main m-file (since it was complete) and some variables as MAT-files ... But during the saving, I think something got wrong with the command
save('filename','variables')
and I accidentally overwrote my main m-file... OK, the next time I will pay more attention and I will backup more often.. Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 8월 30일
You can look to see if there is an auto-save file located in the same folder as your m-file with the same name but extension .asv, like if you have test.m, then look for a test.asv file.
  댓글 수: 2
Sim
Sim 2019년 8월 30일
편집: Sim 2019년 8월 31일
Thanks @Image Analyst!...Unfortunately I cannot see any file with an .asv extension in my folder where I saved my m-file... I am a bit disappointed since it is 1 month of work lost... any other way ? Also, CTRL+Z does not work at all...
Walter Roberson
Walter Roberson 2019년 8월 31일
On Mac, the extension for the backup files tends to be .m~ instead of .asv

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by