Effacer les filtres
Effacer les filtres

Simulink Stop Time from External Input

9 vues (au cours des 30 derniers jours)
Florian Rössing
Florian Rössing le 28 Oct 2021
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?

Réponse acceptée

Jon
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)
  3 commentaires
Jon
Jon le 28 Oct 2021
Sorry, I was editing my answer while you were commenting so we crossed each other. As you can see in my edit, I did realize that you were using parsim, but you still would have to find the final time in each time series and set that explicitly as the stop time. I would think you could set up a loop to do that.
I looked a little further, but I also didn't see a setting so that Simulink would stop at the last point in an input time series. Funny, you would think that would be a natural thing to do. They allow you to extrapolate, set to zero, hold constant, but not just stop
Florian Rössing
Florian Rössing le 29 Oct 2021
Exactly what i was thinking. It is the most trivial thought here.
Now my program is a lot slower, but I will have to stick with that:/
Not the answer I was hoping for, but the correct one.
Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by