What is the difference between .m and .mat files in MATLAB

MatlabFile IoFile Extension

Matlab Problem Overview


When I traced my reference MATLAB script, I found files with the .mat extension. My questions are:

  1. What is the difference between .mat and .m files?
  2. How does one open files with the .mat extension?

Matlab Solutions


Solution 1 - Matlab

Files with a .m extension contain MATLAB code, either in the form of a script or a function.

Files with a .mat extension contain MATLAB formatted data, and data can be loaded from or written to these files using the functions load and save, respectively. You can also access and change variables directly in MAT-files without loading them into memory using the function matfile.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser477670View Question on Stackoverflow
Solution 1 - MatlabgnoviceView Answer on Stackoverflow