Matlab executable doesn't recognize 'sim' and Simulink model

12 views (last 30 days)
Avinash Ayyalasomayajula
Avinash Ayyalasomayajula on 9 Nov 2018
Commented: Walter Roberson on 31 Dec 2021
Hi, I have a Matlab script file to process data stored in an Excel file. In the process Simulink is invoked and the results of the analysis are written into a new Excel file. When run on Matlab, my script runs fine without any errors and gives the expected results. When I create an executable of the same (through the 'Application Compiler' app) and run it from the command prompt, the call to the function ‘sim’ gives an error ('Undefined function or variable 'sim' '). These are the installed products on my computer.
Operating System: Microsoft Windows 7 Enterprise Version 6.1 (Build 7601: Service Pack 1)
Java Version: Java 1.8.0_152-b16 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.5 (R2018b)
Simulink Version 9.2 (R2018b)
DSP System Toolbox Version 9.7 (R2018b)
Image Processing Toolbox Version 10.3 (R2018b)
MATLAB Compiler Version 7.0 (R2018b)
MATLAB Compiler SDK Version 6.6 (R2018b)
Optimization Toolbox Version 8.2 (R2018b)
Signal Processing Toolbox Version 8.1 (R2018b)
Would I need a Simulink Compiler along with Matlab Compiler to make my executable recognize the call to the function ‘sim’. Please let me know.
Thanks in advance!

Answers (1)

Ashutosh Prasad
Ashutosh Prasad on 12 Nov 2018
In order to interface the Simulink model with compiled MATLAB code you will need to build your model as an RSim executable (using Simulink Coder with Rapid-Simulation target). You can then call the RSim executable from your MATLAB code using either the SYSTEM command or the bang (!) operator. If you want to pass new inputs to the Simulink model, you can do so by specifying the input MAT file using the –p flag when calling the RSim target.
Documentation on RSim can be found here
Below is a generic recommended workflow for developing a deployed MATLAB application that uses Simulink.
1 – Develop the application as you normally would to a working state.
2 – Modify the MATLAB code and Simulink model so that all inputs and outputs passed between them are through MAT files.
3 – Build the Simulink model to an RSim target. Change any method for modifying parameters to the workaround mentioned above for modifying parameters. Replace any instances of SIM or equivalent methods of running the model in your MATLAB code with either the SYSTEM command or bang operator(!) calling the RSim executable.
4 – Compile the MATLAB code to an executable using MCC .
  2 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!