M files: They are just a plain ASCII text that is interpreted at runtime.
They are like sub-programs stored in text files with .m extensions and are called M-files.
For most of the MatLab, development M-files is used.
MEX files: They are basically native C or C++ files which are linked directly into the MatLab application at runtime.MEX files have the efficiency to crash the MatLab application.