simulink matlab standalone executable unable to get output

人盡茶涼 提交于 2019-12-24 10:49:59

问题


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.

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

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.

Is my approach to the problem correct?
Should I make a simulink mex file instead?
Thank you in advance for any help.


回答1:


Your general approach is correct. However, there are possibly a couple of things that you haven't done,

  1. In Simulink, the model should be set up to use From File blocks for its inputs and To File blocks for its outputs
  2. In MATLAB, the code needs to be set up to generate a .mat file not only for parameters, but also for the input signals.
  3. 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).
  4. 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.


来源:https://stackoverflow.com/questions/41964437/simulink-matlab-standalone-executable-unable-to-get-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!