MATLAB Answers

0

HOW TO CONVERT .m INTO .mat file

Asked by ASWANT KUMAR SHARMA on 21 Nov 2017
Latest activity Commented on by Jan
on 10 Nov 2018 at 21:10
HOW TO CONVERT .m INTO .mat file?

  0 Comments

Sign in to comment.

1 Answer

Answer by Jan
on 21 Nov 2017

You can't. Or you do not want to. At least you shouldn't.
M-files are scripts or functions. This means, that they contain code. But MAT-files contain data only. You cannot execute them.
Of course, there are some overlapping details: If the M file contains the definition of variables only:
% Your M-file
A = 1;
B = [256; 17];
Then you could store the contents of the created variables in a MAT file. Or if the MAT file contains an object, which triggers the execution of code, when it is initialized - this is the case for .fig files: They are MAT-files with a specific file extension. Opening such a file causes the figure to be constructed and the CreateFcn is called.
But apart from such exceptions, M and MAT files have different jobs and contain different kind of contents.
There I'm sure you want to do something else. Please explain, which problem you want to solve.

  3 Comments

Hi There!
So my problem is that I saved variables as a .m file instead .mat and now I'd like to recover them. Is there really no way to get them back? It's been like days work for such a stupid mistake :(
Thanks!
@Alejandro Turpin: How exactly did you do this? Tell us the exact steps that you used to save that data. There might be ways to get your data back (e.g. it might be as simple as changing the file extension), but unless you tell us what you did and/or upload the data files themselves, we have no idea how/what/why your data is encoded.
Jan
on 10 Nov 2018 at 21:10
@Alejandro Turpin: Please open a new thread to ask a new question. This is the section for comments to an answer to a different question.

Sign in to comment.