MATLAB: Difference between .m and .mat files

MATLAB Compiler

What's the difference betwwen .m and .mat files? can a file from .m format be converted automatically to .mat?
Many thanks in advance for your answer!

Best Answer

  • MATLAB code is in files with extension .M.
  • MATLAB data is in files with extension .MAT.
Thus, you can't always "convert". But if your MATLAB code just contains variable assignments, yes then you can "convert"
Assuming you have a file testm.m with the assigments
a=1
b=2
then you would convert by running the file and then save a MAT file
testm
save('testmat.mat')
Related Question