Clear Filters
Clear Filters

Corrupted .m file

71 views (last 30 days)
Jason
Jason on 28 Aug 2023
Answered: Namnendra on 4 Sep 2023
My laptop was rebooted, and I guess Matlab was open, and some m files had unsaved modifications. When I opened Matlab again, the files were all corrupted with unreadable characters.
There must be a way to extract the text from an m file that happened to not be saved and lose a checksum or something. There is no other modern program that would allow a file to be corrupted because the program was shut down with it in an unsaved state.
The files that were corrupted represent a huge amount of work.
Is there anyone at Mathworks who can help me? This should not be an unsolvable problem.
  12 Comments
Bruno Luong
Bruno Luong on 28 Aug 2023
Yes this is my assumption to. The content byte of the mfiles are somewhere on the HD if there is not much activities, and can hardly be corrupted, just the file system that mess up the files storage.
That what I told you : first make an image copy of the thing and do not mess too much, then you might have to recover with some software.
John D'Errico
John D'Errico on 28 Aug 2023
This is not something a MathWorks person could help with anyway. It really has nothing to do with MATLAB, but your file system has corrupted the file.
m-files are just simple text files. If it is unreadable as a text file, then MATLAB cannot help you.
So first, as of yesterday or last week, you need to start using backups. At least, start that practice TODAY. Backups are the most important thing you can do in this respect.
As well, have MATLAB start making backups for you. In the editor/debugger preferences, click on Backup Files. In there, you can tell it how often to save a backup. If you had done that, then there should be a .asv file on your computer for the files you were writing. It should not be corrupted.

Sign in to comment.

Answers (1)

Namnendra
Namnendra on 4 Sep 2023
Hey Jason,
I understand the frustration of losing unsaved modifications in MATLAB due to a reboot. Unfortunately, if the files were not saved and were corrupted upon reopening MATLAB, it is unlikely that the original text can be recovered directly from those files.
However, there are a few steps you can try to recover the lost code:
1. Check for temporary files: MATLAB creates temporary backup files with a `.asv` extension. These files might contain some of your unsaved modifications. You can search for files with the `.asv` extension in the same directory as your corrupted files.
2. MATLAB Recovery Folder: MATLAB has a recovery feature that automatically saves backups of open files. You can check the MATLAB recovery folder to see if any recoverable versions of your files exist. The location of recovery folder depends on your operating system. For Windows, the default location is usually `C:\Users\YourUsername\AppData\Local\Temp\MathWorks\Matlab\R20XXx\`.
3. Version Control System: If you were using a version control system (e.g., Git, SVN) or had the files stored in a cloud-based service (e.g., GitHub, Dropbox), you might be able to recover an earlier version of the files from the repository or cloud storage.
4. Text Recovery Tools: There are some third-party tools available that can attempt to recover text from corrupted files. These tools use various techniques to extract readable text from damaged files. However, the success rate can vary, and it's not guaranteed to recover the complete code.
In the future, it's always a good practice to save your modifications periodically while working on MATLAB or any other program to avoid losing unsaved changes due to unexpected events like system reboots or crashes. Additionally, enabling autosave features or using version control systems can provide an extra layer of protection for your code.
I hope this helps.
Thank you

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!