Azzera filtri
Azzera filtri

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

399 visualizzazioni (ultimi 30 giorni)
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 Commenti
Image Analyst
Image Analyst il 12 Set 2019
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 il 28 Apr 2024 alle 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.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 31 Ago 2019
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 Commento
Sim
Sim il 31 Ago 2019
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!

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 30 Ago 2019
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 Commenti
Sim
Sim il 30 Ago 2019
Modificato: Sim il 31 Ago 2019
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...

Accedi per commentare.

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by