Corrupted .m file

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 commentaires

Bruno Luong
Bruno Luong le 28 Août 2023
Modifié(e) : Bruno Luong le 28 Août 2023
Not sure. mfile is just a simple ascii file. IMO there are just 2 type UTF8 or UTF16. There is no checksum or header.
MATLAB editor does let the file in open state. It saves a previous version in *.asv.
IMO it is not the files that are corrupted but the file system or the HD.
May be your should first backup the image of HD before doing any manip the can not be reversed.
Jason
Jason le 28 Août 2023
How is it possible that an ascii file could be completely corrupted?
Star Strider
Star Strider le 28 Août 2023
This sounds like some of the random immediate shutdowns common to Win 11 over the last several months.
First, see if rebooting three or four times without opening MATLAB resolves the issue. Otherwise, if you know what some of the characters are, see if there is any common pattern to the correct and corrupted characters (addition or multiplication by a constant, bit-shifting, etc.). Another option is to see if MathWorks has heard of this before and has a fix for it (even though it¹s likely not a MathWorks or MATLAB problem).
Jason
Jason le 28 Août 2023
The characters are completely unreadable in matlab editor or notepad. Format-hex shows no readable characters either. It all looks like this:
Jason
Jason le 28 Août 2023
I guess the characters are non-ascii as they didn't go through in the post.
Jason
Jason le 28 Août 2023
I submitted a service request to Mathworks.
Star Strider
Star Strider le 28 Août 2023
FWIW, whenever Win 11 does one of those unscheduled immediate shoutdowns, I always reboot at least four times without opening anything (other than the ‘Event Viewer’ app to see what the problem was). Win 11 can leave some strange apps up and open otherwise, and repeated rebooting shuts them down and keeps them shut down.
Walter Roberson
Walter Roberson le 28 Août 2023
Windows 11 has that strange behaviour where it treats a request to shutdown as a request to suspend, so if you really want to shutdown you have to take additional steps.
Jason
Jason le 28 Août 2023
I think it might actually be the filesystem. The files were on a SD drive, and it seems like the file address has been corrupted.
Walter Roberson
Walter Roberson le 28 Août 2023
Sadly, in such cases, you often need to resort to backups.
Even students should be running backups every few hours -- according to how much work they can afford to lose.
Bruno Luong
Bruno Luong le 28 Août 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 le 28 Août 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.

Connectez-vous pour commenter.

Réponses (1)

Namnendra
Namnendra le 4 Sep 2023

0 votes

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

Catégories

Produits

Version

R2023a

Question posée :

le 28 Août 2023

Community Treasure Hunt

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

Start Hunting!

Translated by