How to find Matlab version to be used in the mex file header
Show older comments
I create a mex file that compiles and works properly in R2010b and up, versions I have at my work. But I need the same file be used in R2010a, since that's the version I have in my laptop. If I used in R2010 I have an error. I found the code need it to make it work. But every time I switch I have to comment and uncomment. Is there any way to find Matlab's version in the header? Let me give some code:
#include <stdlib.h>
#include <vector>
#include <queue>
#include <limits>
#include <utility>
#include <map>
#include <assert.h>
#include <stdio.h>
/* #ifdef _CHAR16T //for matlab 2010a
#define CHAR16_T
#endif */
#include "mex.h"
#include "matrix.h"
using namespace std;
........code ............
The commented section is my fix. I want to find Matlab's version and put an if statement so it automatically applies my fix. I try this:
int i;
int j;
sscanf(version,'%d.%d %*s',&i, &j)
#if i<=7 && j<11
#ifdef _CHAR16T //for matlab 2010a
#define CHAR16_T
#endif
#endif
but it did not work since c++ did not find the "version" variable defined in matlab. Does somebody know how to do that? I really appreciate any help!
Accepted Answer
More Answers (2)
James Tursa
on 10 Apr 2019
1 vote
Version info for mex routines can be found in this FEX submission:
Kaustubha Govind
on 17 Nov 2011
You can use the ver command to obtain version information in MATLAB:
>> v=ver('MATLAB')
v =
Name: 'MATLAB'
Version: '7.13'
Release: '(R2011b)'
Date: '08-Jul-2011'
However, it's not clear to me how you plan to use this information in your MEX-file. Since #defines are used by the pre-processor, what you're doing won't work at run-time. Do you plan to re-compile the C code every time before it is executed?
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!