Matlab executable doesn't recognize 'sim' and Simulink model
조회 수: 8 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
Ashutosh Prasad
2018년 11월 12일
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.
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.
댓글 수: 2
Walter Roberson
2018년 11월 12일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 DSP Algorithm Acceleration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!