C Mex MATLAB Version

Mex C code to determine MATLAB version at compile time and run time

現在この提出コンテンツをフォロー中です。

This submission provides the following files to assist the programmer in creating robust C/C++ mex code that can compile and run under multiple MATLAB versions:
(1) matlab_version.h provides pre-processor code that defines the macro MATLAB_VERSION, which will contain the hex number equivalent of the MATLAB version that is being used for the compile (e.g., a value of 0x2015b would indicate MATLAB version R2015b). It also defines the macro TARGET_API_VERSION to differentiate between the R2017b and R2018a API libraries being used. And it contains a prototype for the matlab_version() function that is contained in the matlab_version.c file.

(2) matlab_version.c provides code for the matlab_version() function, which returns the hex number equivalent of the MATLAB version that is currently being run. (via a mexCallMATLAB callback)

(3) matlab_version_test.c provides code for a mex routine that tests matlab_version.h and matlab_version.c

(4) matlab_version_test.m provides m-code that will automatically compile the matlab_version_test.c file.

To test all of this, simply type at the command line:

>> matlab_version_test

There are also extensive comments at the front end of the matlab_version.h file that describe an assortment of mxArray and API changes over the years. The idea is that the macro MATLAB_VERSION can be used to determine whether various library functions or features that the programmer is depending on are actually available in the version being used for the compile. E.g., the programmer could use an #if - #else - #endif block to conditionally compile different code depending on the value of MATLAB_VERSION. And the matlab_version( ) function result can be used to determine if a MATLAB function the programmer wants to call with mexCallMATLAB is actually available in the current version of MATLAB being run.

Tested under various Win32 and Win64 versions of MATLAB from R2009a - R2018a.

引用

James Tursa (2026). C Mex MATLAB Version (https://jp.mathworks.com/matlabcentral/fileexchange/67016-c-mex-matlab-version), MATLAB Central File Exchange. に取得済み.

カテゴリ

Help Center および MATLAB AnswersWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

一般的な情報

MATLAB リリースの互換性

  • すべてのリリースと互換性あり

プラットフォームの互換性

  • Windows
  • macOS
  • Linux
バージョン 公開済み リリース ノート Action
4.1.0.0

Updated notes for R2019a mxArray CrossLink field move.

4.0.0.0

Updated notes for mxArrayToString and mxArrayToUTF8String API functions.

3.0.0.0

Updated the comments for R2018a, and split the matlab_version() code and the mex test code into two separate files.

2.0.0.0