MATLAB: How to restore a previous version of an m-file that I have accidentally overwritten with a MAT-file

overwritten m-file

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

Best Answer

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.
Related Question