Simulink Matlab独立可执行文件无法获取输出 [英] simulink matlab standalone executable unable to get output
问题描述
我有一个M脚本,该脚本通过GUI从用户那里获取参数值,然后使用更新后的参数值模拟simulink模型.我想将其转换为一个独立的exe文件,该文件无需Matlab& Simulink(即仅适用于Matlab Runtime Compiler).我正在使用32位MATLAB 2010b.
I have a M-script which takes the parameter values from user via a GUI and then simulates a simulink model with the updated parameter value. I want to convert it into a standalone exe file which can run without Matlab & Simulink (i.e. only with Matlab Runtime Compiler). I'm using MATLAB 2010b 32bit.
我的方法:
由于Matlab编译器无法转换 sim 函数,因此我首先使用Rapid Simulation目标将Simulink模型转换为exe文件,然后从matlab脚本中调用该exe文件.
My approach:
As the Matlab compiler cannot convert the sim function, I first converted my Simulink model to an exe-file using the Rapid Simulation target and then called the exe file from my matlab script.
[Gain1, Gain2]= InputDataGUI;
load Par.mat %contains parameter structure of the model
param_struct.parameters.values(1:2) = [Gain1 Gain2]; %update
save Par.mat param_struct;
!SimulinkModelName.exe -p Par.mat
save results.mat
此脚本可在Matlab中正常运行.最后,我使用 deploytool 将M文件以及所有其他必需文件打包到一个exe文件中.最终的exe文件运行GUI,并保存更新的Par.mat文件,但不提供模拟结果文件.我还尝试了 To File 块来保存结果.我认为该脚本无法运行仿真.
This script works in Matlab without errors. Finally I packaged the M-file along with all the other required files into an exe using the deploytool. This final exe-file runs the GUI and saves the updated Par.mat file but doesn't give the simulation result file. I have also tried the To File blocks for saving results. I think the script is unable to run the simulation.
我解决问题的方法正确吗?
我应该改为制作simulink mex文件吗?
预先感谢您的帮助.
Is my approach to the problem correct?
Should I make a simulink mex file instead?
Thank you in advance for any help.
推荐答案
您的一般方法是正确的.但是,可能还有几件事您还没有做完,
Your general approach is correct. However, there are possibly a couple of things that you haven't done,
- 在Simulink中,应将模型设置为使用
From File
块作为输入,使用To File
块作为输出 - 在MATLAB中,需要设置代码以不仅为参数而且为输入信号生成.mat文件.
- 运行模拟时,使用
-p
指定参数,使用-f
指定输入文件(如果要覆盖模型本身中指定的文件),使用-o
指定输出文件的名称.您要写入数据(如果要覆盖模型本身中指定的数据). - 在您(已部署的)MATLAB代码中,您需要读取生成的.mat文件以存储输出,并对其进行适当处理(即绘制).
- In Simulink, the model should be set up to use
From File
blocks for its inputs andTo File
blocks for its outputs - In MATLAB, the code needs to be set up to generate a .mat file not only for parameters, but also for the input signals.
- When running the simulation use
-p
to specify parameters,-f
to specify the input file (if you want to override the one specified in the model itself), and-o
to specify the name of the output file you want the data written to (if you want to override the one specified in the model itself). - In your (deployed) MATLAB code you need to then read the .mat file generated to store the output, and process it (i.e. plot it) appropriately.
这篇关于Simulink Matlab独立可执行文件无法获取输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!