MATLAB: Matlab-built application with using rsimsetrtpparam throws error

application builderMATLABrtwsimulink

Hey there, I am struggling with a problem thrown by my built Matlab-Application.
In short, what I am trying to do with the .exe:
  • Aim: load and calculate Parameters, then write .mat-Parameterfile for a compiled Simulink-Application. Similar to: openExample('simulinkcoder/UseRSimTargetForBatchSimulationsExample')
So, more detailed:
  • Matlab-App reads some parameters from file (works)
  • Matlab-App calculates some stuff with these parameters (works)
  • Matlab-App loads a working RTP-Parameterfile. Then it should add the parameters using rsimsetrtpparam() and afterwards saving the new parameterfile (as .mat). ( does not work)
The error is thrown when executing the .exe in the command line:
Undefined function or variable 'sl'.
Error in rsimsetrtpparam (line 43)
...
MATLAB:UndefinedFunction
But the pop-up error message box says another / additional error:
Undefined function 'sl' for input arguments of type 'struct'. Error in => MyApp.m at line xy
I already tried to include the 'sl'-function from MATLAB\R16b\toolbox\simulink\simulink\sl.m in the "Files required to run your Application" in the Matlab Application builder, but the error remains.
So what might solve this problem? Is there a problem using structs in built Matlab-Applications?
Appreciating every kind of help,
AL
edit: the code works well when running in matlab, but even not if built.

Best Answer

So I finally got it solved by diving into the Matlab-Directories.
All depends on the modifyRTP.p , located in toolbox/simulink/simulink/private. You have to add this file to "Files required for your application to run" in the Matlab Compiler UI, as well as the file "sl.m". Then it all works.