MATLAB Answers

0

How to tell if Simulink has been run from Matlab or direct from Simulink

Asked by Rob Child on 19 Mar 2017
Latest activity Answered by Alisha Schor on 21 Mar 2017
I have a simulink model with a Call-Back that, amongst other things, asks the user which case they want to run and reads that case's data from a spreadsheet. To do the user is asked via a simple Matlab dialogue box to enter an integer.
However, I now need too build a batch mode, were Matlab will be in charge and run multiple simulations, specifying what the integer should be without the need for an dialogue box.
Q: How can I get Simulink and it's Matlab code in callbacks to know whether it has been run by hitting the green run button or by the "sim" command or similar in Simulink
Given that the model will sometimes break, it would be nice not to rely on the external Matlab code doing the running to have to positively remember to cancel the batch mode.
Or maybe one of the more mysterious callbacks might help me? Thanks

  0 Comments

Sign in to comment.

1 Answer

Answer by Alisha Schor on 21 Mar 2017

From Simulink's perspective, the "sim" command and the green Run button are the same, so there is not a way to distinguish how the model was run. I would suggest setting a flag where the default value corresponds with the "green button run", and if the flag is set, use the dialog box. Then, in your batch script, you can override the value of the flag so that the dialog box does not get called. Something like:
PreLoadFcn contains:
flag = 1
InitFcn contains:
if flag
% call dialog box
else
% read parameter value
Batch script contains:
flag = 0;
% set parameter value

  0 Comments

Sign in to comment.