C Mex MATLAB Version
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.
Cite As
James Tursa (2024). C Mex MATLAB Version (https://www.mathworks.com/matlabcentral/fileexchange/67016-c-mex-matlab-version), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > External Language Interfaces > C with MATLAB > Write C Functions Callable from MATLAB (MEX Files) >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
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 |