Simulink Stop Time from External Input

4 次查看(过去 30 天)
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
Jon 2021-10-28
编辑:Jon 2021-10-28
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 个评论
Jon
Jon 2021-10-28
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 2021-10-29
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by