Simulink Stop Time from External Input
3 次查看(过去 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?
0 个评论
采纳的回答
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!