MATLAB: Is there a way to determine if the MATLAB code is running in the MATLAB environment or as a standalone application created using MATLAB Compiler 4.0 (R14)

environmentm-codeMATLABMATLAB Compilermodestand-alonestandalone

I would like to know if there is a way to determine if the MATLAB code compiled by the MATLAB Compiler is running in the MATLAB environment or as a standalone application.

Best Answer

When using the MATLAB Compiler 4.0 (R14) or later, the ISDEPLOYED function can be used to determine if MATLAB code is executing in a MATLAB environment or in a deployed environment. For more information on this function, enter the following at the MATLAB command prompt:
doc isdeployed
For previous versions of the MATLAB Compiler, there is no function or API call that can be used to identify if your compiled MATLAB code is being executed in the MATLAB environment or running as a standalone application.
As a workaround, you can include and use the following function to determine if your code is being run in a standalone mode:
function v = iscompiled
v = false;
if( exist('v') ~= 1)
v = true;
disp('This is a standalone application')
else
disp('This is in MATLAB environment')
end
The above function will return "true" if it is executed in standalone mode and "false" when executed in MATLAB environment.