1
votes

Matlab provides the sim command that can be used in a Matlab script to call and execute a Simulink model. But the function seems to be restricted to models that only run in Normal mode. When I try to call a Simulink model that runs in External mode, Matlab halts the script and flags it as an error. Besides being a nuisance it seems to me an unnecessary restriction on what could be a very useful application.

In any event is there a work around, perhaps a different command that I can use to run the Simulink diagram in External mode from the Matlab script?

I did try using the Matlab DOS shell command (using !) but it requires opening another instance of Matlab.

1

1 Answers

4
votes

External Mode doesn't run a simulation, rather it is a mechanism for using the Simulink model's front end as a way of changing and viewing data that is running elsewhere (e.g. an executable running on the same machine as the model, or code running on an external processor).

To do that from the command line (or within code) you need to use a combination of the following commands:

>> set_param(gcs,'SimulationMode','external') % put model into External Mode
>> set_param(gcs,'SimulationCommand','connect') % connect to the executable
>> set_param(gcs,'SimulationCommand','start') % Start the executable
>> set_param(gcs,'SimulationCommand','stop')  % Stop the executable