MATLAB: Using MATLAB Class with coder.ceval calls in App designer

app designerclasscompilerfunctionmatlab coderMATLAB Compiler

Hello People,
i am trying to use a MATLAB class inside of my App designer application. The usage of the class works fine as in debug mode the objects are created correctly.
Some of the functions in the MATLAB class use coder.ceval function as some C-code is used. The Class works fine when using the corresponding Simulink Block in Simulink Compiler.
Trying to compile the Standalone Applikation i always get the error: coder.ceval is not supported in MatLab.
Inside the Class i am using coder.cinclude correctly and also coder.updateBuildInfo.
Can anyone tell me what the Problem might be? Is the Standalone Applikation not compiled?
Thanks for the help, best regards

Best Answer

Hi Noah, you are correct.
Some background:
  1. MATLAB Compiler (standalon application) is NOT a compiler. It is a deployment tool that packages MATLAB and your program into a single application. When the application runs, the MATLAB is started and your program is executed. So, if your program does not run in MATLAB, it will not run in MATLAB Compiler (Standalone Application) either.
  2. coder.ceval is a function that only works in code generation products (MATLAB Coder and MATLAB blocks in Simulink that use code generation mode, such as MATLAB Fucntion block). That's why your program works fine inside Simulink or inside Simulink compiler, because coder.ceval is supported there, but not supported in MATLAB itself.
Now, what can you do:
  1. You can use MATLAB Coder to generate a MEX file for your function that contains coder.ceval, and then deploy that MEX file as part of your application.
  2. Or you can rewrite the program (the part that uses coder.ceval) to avoid using C code.
  3. You can also use clibgen (MATLAB's C/C++ interface) instead of coder.ceval, though I am afraid you may lose Simulink compatiblity then.
  4. You can also use coder.target to have conditional code to use ceval in Simulink and some other solution in pure MATLAB.
Overall, I don't see an easy solution for your case, as there is currently no simple way to get MATLAB/C integration that works with both MATLAB and Simulink and both compilers. I'll bring this to the MATLAB development team as a feature request for future release.