Simulink Stop Time from External Input
12 vues (au cours des 30 derniers jours)
Hi everyone, I have a relatively simple question but cannot find the answer.
I want to run several hundred simulations from pregenerated data using parsim.
The generated signals are stored as Timeseries in a Dataset Ref object. The signals all have very different length in time, as this depends on the signal characteristics.
Is there any way to have my model derive the StopTime parameter from the input TimeSeries at simulation time? How would I set this up?
Jon le 28 Oct 2021
Modifié(e) : Jon le 28 Oct 2021
You can run simulation models programatically using the sim command. You can get the documentation for that by typing doc sim on your MATLAB command line. This allows you to specify name, value pairs. so for example
tStop = 30; % you could have additional code to determine stop time
simout = sim('myModel','StopTime',num2str(tStop)) % even numerical parameters must be sent as strings
It is a little more complicated using parsim. You have to first create simulink simulation object and then set its parameters. Something like this. I show it just for one model but you could do it in a loop for multiple model runs.
% make a simulink simulation input object
in = Simulink.SimulationInput('myModel')
% set the stop time parameter
tStop = 45; % you could have more code to determine stop time
in = in.setModelParameter('StopTime',num2str(45))
% run the simulation
simout = parsim(in)