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

371 ビュー (過去 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
  2 件のコメント
Sim
Sim 2019 年 8 月 30 日
編集済み: Sim 2019 年 9 月 11 日
I guess my problem is similar to (or the same!)
  1. https://stackoverflow.com/questions/26202119/matlab-code-turned-into-unreadable-symbols
  2. https://ch.mathworks.com/matlabcentral/answers/419197-i-saved-an-m-file-in-matlab-and-it-was-overwritten-i-can-t-find-a-way-to-recover-my-file-because-th
I would have two questions for the MATLAB staff:
  1. Considering the above mentioned links, at least 3 people (myself included) got this problem, losing their works... and accidentally.... Then, why don't you create a command like CTRL+Z to go back to the previous saved versions of m-files, for preventing users to permanentliy overwrite their m-files ?
  2. By checking the default options in Matlab > Preferences > Editor Debugger > Backup Files, I found that "Close Options: Automatically delete BackUp files when the Editor closes" was ticked (i.e. with a check mark)... This means that if I accidentally close the Editor or Matlab, I automatically lose the only hope to get a back-up file, when I overwrite (accidentally) my m-files... Obviously it is my fault since I did not pay enough attention, but is that default option good ?
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.)

サインインしてコメントする。

採用された回答

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 Center および File ExchangeDebugging and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by