MATLAB: HOW TO CONVERT .m INTO .mat file

conversion help

HOW TO CONVERT .m INTO .mat file?

Best Answer

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.