I have recovered some of my m-files after formatting my partitions.
But sadly, found them corrupted. Is there anyway to fix them?
Thanks.
Edited: The code becomes like the attached image.

10 commentaires

Walter Roberson
Walter Roberson le 28 Juil 2017
Not really enough information about the kind of corruption.
Ezz El-din Abdullah
Ezz El-din Abdullah le 28 Juil 2017
Thank you. I have edited my question.
Stephen23
Stephen23 le 28 Juil 2017
Modifié(e) : Stephen23 le 28 Juil 2017
@Ezz El-din Abdullah: your screenshot clearly shows a .mat file (and certainly not an M-file as you wrote in your title and question), and it looks pretty normal for a compressed .mat file. How are you trying to open the .mat file? What error messages do you get?
John D'Errico
John D'Errico le 28 Juil 2017
The header does say .mat file there. And of course you cannot read a .mat file with a text editor.
Regardless, .mat file, or .m file, in either case, if you cannot read them using either load or edit, as appropriate for that file type,
The answer is you cannot really fix what may be missing, if some of the blocks from the file have been dropped out or corrupted. You have lost information. A .mat file is worse in that respect.
Ezz El-din Abdullah
Ezz El-din Abdullah le 28 Juil 2017
@Stephen Cobeldick, I think there was the same name for both .m and .mat files.
Btw, I have used load to open .mat file but produced another error but I'm concerned now to solve the .m file.
So I have attached the result of a .m file only.
Stephen23
Stephen23 le 28 Juil 2017
Modifié(e) : Stephen23 le 28 Juil 2017
@Ezz El-din Abdullah: the answer to your question is to get the latest file version from your version control system, which is of course kept backed up externally to your working computer. Of course like all sensible programmers you use a version control system with backup.
Ezz El-din Abdullah
Ezz El-din Abdullah le 28 Juil 2017
@Stephen Cobeldick, so it has no solution unless I had already used a backup?
Rik
Rik le 28 Juil 2017
If you haven't followed Stephens advice, take mine: at the very least have your working folder in dropbox/google drive/skydrive/whathever.
For your current problem: you could try with Notepad++ to play around with what encoding this might be in, although I fear this file is a loss. It looks more like what I would expect from a .mat file than an .m file.
Walter Roberson
Walter Roberson le 28 Juil 2017
Can you attach one of the m files for us to examine?
Ezz El-din Abdullah
Ezz El-din Abdullah le 28 Juil 2017
@Rik Wisselink, unfortunately Notepad++ does NOT solve the problem.
@Walter Roberson, I think it can't be retrieved.
Thank you all.

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 28 Juil 2017

0 votes

No. If any byte has been lost in an M or MAT file, the contents is destroyed and cannot be recreated with a 100% reliability. If the files have been lost due to a crashed hard disk, I would not even trust in files which look fine on first view. To control this, I store an MD5 checksum in each of my M-files.
The solution is to restore the files from the last backup. All changes since the last backup are lost. If you do not have a backup: Sorry. There is no magic way to reinvent the destroyed data. It is hard, but the general rule is:
All files without a current backup are not important.
Sometimes professional services can save data from crashed hard disks. This costs about 500 to 1500 US$ and the success is not guaranteed.

2 commentaires

Ezz El-din Abdullah
Ezz El-din Abdullah le 28 Juil 2017
I wonder how I can make a backup?
Do you mean intuitively to save my files into other place? like in the cloud.
Steven Lord
Steven Lord le 28 Juil 2017
One quick way to make a backup, as Rik Wisselink suggested, is to copy your files to Dropbox, Google Drive, etc. or even to a USB key periodically.
You could use MATLAB Drive Connector to upload your files to MATLAB Drive.
If you're using release R2014b or later, a more sophisticated way to back up your code (and allow you to go back to any previous version you've checked in) would be to use the source control integration functionality included in MATLAB to make a Subversion or Git repository.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Centre d'aide et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by