Matlab executable doesn't recognize 'sim' and Simulink model
6 次查看(过去 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!