I am using a Simulink to collect data real-time from drop tests. The Simulink works great, but my vision is to have a Matlab (v.7.10) script run the simulation for several trials without me having to run over to the computer between drops. This also allows me to pre-process the data before saving it. Both programs work great individually, but I cannot make the Simulink run properly in a script. Using sim() returns the error message:
Cannot perform command line simulation of 'acc_DAC' in external mode.
Using set_param(sys, 'SimulationCommand', 'start') starts the simulation, but does not block the script. The script continues and returns errors because the outputs it is supposed to have don't exist yet. Notably, I read elsewhere that pausing Matlab will pause any simulations as well, though I couldn't get that far myself.
The Simulink runs until the impact is measured, and then stops and outputs accelerometer data to the workspace. What I am asking is:
A) Is there a way to sim() run an external, real-time simulation?
B) Is there a good way to make Matlab wait for either Simulink to finish, or variables to exist, without pausing the Simulink?
You could try checking the SimulationStatus of the running model, and loop until it says stopped, although you'll need to be a little careful as there's a chance of entering an infinite loop.
Something like
set_param(sys,'SimulationCommand','start');
while ~strcmp(get_param(sys,'SimulationStatus'),'stopped')
drawnow
end
The above will not work in any simulation mode, but may work in external mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With