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

15 visualizaciones (últimos 30 días)
Avinash Ayyalasomayajula
Avinash Ayyalasomayajula el 9 de Nov. de 2018
Comentada: Walter Roberson el 31 de Dic. de 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!

Respuestas (1)

Ashutosh Prasad
Ashutosh Prasad el 12 de Nov. de 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 comentarios
Walter Roberson
Walter Roberson el 12 de Nov. de 2018
Note that in particular MATLAB Compiler and MATLAB Coder cannot be used for code that calls any Simulink function. Nothing in the Simulink family can be processed by MATLAB Compiler or MATLAB Coder.
Ashutosh has described the flow for using the appropriate Simulink products to build a separate executable that can be started by a MATLAB Compiler produced executable.
More generally there are possible approaches to have the two sides interact with each other "live", such as using tcp.
Walter Roberson
Walter Roberson el 31 de Dic. de 2021
As of R2020a, you can use Simulink Compiler.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by