I am converting a subset of MATLAB files from a GUI into MEX files. I want to provide the user the option to run the original MATLAB files or the MEX files once they have been generated. I imagined that the user could select which they would like to from the GUI.
There are a number of ways to go about this, but I thought that the following would be the least "bulky" in terms of code: using the same MATLAB file to either a) generate a MEX function, b) run the MATLAB code, or c) run the MEX code. Below is a code example of how I thought to implement this.
function output = my_func(input1, input2, code_flag, matlab_flag)
coder.extrinsic('my_func_mex');
if code_flag == 1 || matlab_flag == 1
output = input1 + input2;
else
output = my_func_mex(input1, input2, code_flag, matlab_flag);
end
The call to generate the MEX function would be done outside of this file using the following command:
codegen my_func -args {coder.typeof(0, [1, 5], [0, 0]), coder.typeof(0, [1, 5], [0, 0]), 1, 1}
I am able to compile the code and build the MEX function, but if I try to run my_func with the flags set to false, i.e. run the MEX version, MATLAB crashes. Why? Is what I am trying to do not possible? If not possible, why?