What is the difference between MATLAB code files, pCode and MEX files?

6 ビュー (過去 30 日間)
Doug Hull
Doug Hull 2011 年 1 月 18 日
I hear about all of these, but do not know how they differ.

採用された回答

Doug Hull
Doug Hull 2011 年 1 月 18 日
  • M-files are plain ASCII text that is interpreted at run time. Actually it is parsed once and "just-in-time" compiled, but this is transparent to the user. Use M-files for most of your MATLAB development, and for platform independence and maintainability.
  • Pcode is a preparsed and encoded version of the M-file. Since it is preparsed, it saves on the load time of the function. This is most likely not an issue except for very large M-files, since most are parsed only once anyway. Pcode also lets you hide the source code from others. Careful, there is no way to convert Pcode back to the M-file source. Pcode is platform independent.
  • MEX files are native C or C++ files that are dynamically linked directly into the MATLAB application at runtime. They must be compiled for each hardware architecture on which they are to be run. MEX files have the potential to crash the MATLAB application, but rather large speed gains are possible, depending on the algorithm.
[From the MATLABFAQ of Ancient Times]
  2 件のコメント
James Tursa
James Tursa 2011 年 2 月 3 日
MEX files can also be Fortran source :)
Another difference is that arguments to MEX routines are passed by reference whereas arguments to m-files are passed a shared-data-copy. One exception is that cell or structure field references are resolved before the MEX routine is called, so in those cases the MEX routine gets passed a shared-data-copy of the cell or structure field. Another difference is that MEX routines can be MATLAB version dependent, so a MEX routine compiled under one MATLAB version may not run under another MATLAB version, even on the same machine.
James Tursa
James Tursa 2012 年 4 月 27 日
Also, Pcode is MATLAB version dependent. Pcode generated under one MATLAB version may not run under a different MATLAB version.

サインインしてコメントする。

その他の回答 (2 件)

Alexei
Alexei 2011 年 2 月 12 日
I actually want to add a question ))
I know you can turn .m code to C files using the MCC and then turn that to a MEX dll
Question is, can you turn .p code to C using MCC and then turn to a MEX dll?
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 2 月 12 日
mcc cannot turn .m files to C using any version for a number of years now. mcc produces data files that contain threaded interpreted code, not C code. mcc has no problem including .p files in producing the final result.

サインインしてコメントする。


Rui
Rui 2012 年 4 月 27 日
is there any difference in performance on using the MCC to build a standalone application or matlab compiled dll to be called within a C/C++ application?
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 4 月 27 日
No, other than perhaps differences in the start-up time (and those differences could depend upon whether a graphics window was being created.)
However, in the other question you were asking about this, you were talking about converting code to C or C++. Converting code to C or C++ is handled by MATLAB Coder, not MATLAB Compiler, and the result would run at the speed of C (or C++), not at the speed of MATLAB. The trade offs is that MATLAB Coder is expensive and there are quite a number of things that cannot be compiled with it.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by