Simulink Stop Time from External Input
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Florian Rössing
el 28 de Oct. de 2021
Comentada: Florian Rössing
el 29 de Oct. de 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?
0 comentarios
Respuesta aceptada
Jon
el 28 de Oct. de 2021
Editada: Jon
el 28 de Oct. de 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 comentarios
Jon
el 28 de Oct. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Programmatic Model Editing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!