How to find Matlab version to be used in the mex file header
6 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Jan
2011-11-17
Does the problem concern the Matlab version, or is it caused by different compilers?
Would it work to check if CHAR16_T is defined already?
#ifndef CHAR16_T
Butr if the problem really concerns the Matlab version, I suggest to append a flag to the MEX call:
function myMex(varargin)
V = [100, 1] * sscanf(version, '%d', 2); % Consider 7.10!
if V < 711
Flag = {'-DNEED_CHAR_16_T'};
else
Flag = {};
end
mex(varargin{:}, Flag{:});
I started with some equivalen flags to distinguish Matlab 5.3 and 6.5. Meanwhile my enhanced MEX function has 500 lines, considers different mexopt.bat files, e.g. enable SSE2 commands under 32-bit Matlab, but avoid this under 64 bit, if MSVC2010 ist used, etc.
1 个评论
Steven Lord
2019-4-10
V = [100, 1] * sscanf(version, '%d', 2); % Consider 7.10!
The verLessThan function was introduced in release R2007a. You can wrap it in a try / catch statement if you need to run the code in release R2006b or earlier, and use this technique in the catch block to distinguish release R2006b and earlier releases.
更多回答(2 个)
Kaustubha Govind
2011-11-17
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?
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!