1

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.

Aastha
  • 11
  • 2

1 Answers1

2

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.
Phil Goddard
  • 10,571
  • 1
  • 16
  • 28
  • Hi Phil. Thanks for your reply. – Aastha Feb 01 '17 at 13:52
  • I have checked and I am following all these points already. Currently I am just testing with a Sine input. So, no need of an input file. And i am using 'To File' to store the outputs. I am also just testing with default output file name. After some testing I think it is not possible to pack an exe-file in another exe file. I have discovered today that when I run the final exe file (made from deploytool) in Matlab, it cannot access the Simulink Model exe. I get the error " The command SimulinkModelName.exe is either incorrectly written or could not be found" – Aastha Feb 01 '17 at 14:12
  • @Phil, thanks for the information. Is there any official MathWorks documentation detailing the arguments available on the standalone exe? – JZYL Jul 13 '18 at 19:51