M files: They are just a plain ASCII text that is interpreted at run time. 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 are used.
MEX files: They are basically native C or C++ files which are linked directly into the MatLab application at runtime. MEX files have efficiency to crash the MatLab application.