Make your MATLAB code work everywhere

MATLAB is used in many different setups that it’s hard to expect every line of your code you write generalizes to all other versions, platform and deployments. The following code examples helps you identify what envirnoment you are in and so you can branch accordingly:

% 32 bit vs 64 bit MATLAB
% This exploits the fact that mex is on the same platform as your MATLAB
is64bit = strcmpi( mexext(), 'mexw64');

% Handling different MATLAB versions
if( verLessThan('matlab', yourVersionString) )
error('This code requires %s or above to run!', yourVersionString);
end

% Headless (Parallel) workers
% This exploits the fact that JVM is not loaded for parallel workers.
% Starting MATLAB with '/nojvm' will be considered headless

% DCOM / ActiveX /Automation Server
isDCOM = enableservice('AutomationServer');

% Test for compiled MATLAB:
isdeployed()

1,326 total views,  1 views today

Subscribe
Notify of
1 Comment
Inline Feedbacks