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

395 visualizaciones (últimos 30 días)
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 comentarios
Image Analyst
Image Analyst el 12 de Sept. de 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 el 28 de Abr. de 2024 a las 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.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 31 de Ag. de 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 comentario
Sim
Sim el 31 de Ag. de 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!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 30 de Ag. de 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 comentarios
Sim
Sim el 30 de Ag. de 2019
Editada: Sim el 31 de Ag. de 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...

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by