Run Simulink Model iteratively from .m code
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ruprecht Altenburger
el 17 de Ag. de 2023
Respondida: Sulaymon Eshkabilov
el 17 de Ag. de 2023
Hello
Within a Matlab script I want to run a (not too complicated) Simulink model in many iterations such that the Simulink model continues from the last state, like:
- in .m file do calculations for a new timestep,
- based on that: run Simulink, store all model states
- in .m file, do next calculations
- contine Simulink model from the previous state
This loop would run e.g. 1000x. I tried to do it the other way around and embedded the .m code within Simulink. But the Compiler did not work (many different dynamic classes in the .m code)
0 comentarios
Respuestas (1)
Sulaymon Eshkabilov
el 17 de Ag. de 2023
This exercise of yours can be done in a few different ways.
(1) Store time steps (time array) along with the input data in a cell array, e.g. Data or initially specify time step size if known
(2) Employ sim() to run your Simulink model from MATLAB environment.
(3) In Simulink model, use [From WorkSpace] and [To WorkSpace] blocks, which are used to get the data from MATLAB workspace to simulate the model and send the results back to MATLAB workspace.
(4) In MATLAB code, use sim() to run the SImulink model within a loop. E.g.:
Data = ...
for ii = 1:1000
IN = Data{ii}; % Call [IN] for simulation using [From WorkSpace] block variable's name is IN
OUT{ii}= sim('M_Run.slx'); % Simulation results from the Simulink model M_Run.slx. All simulation results saved under the var name OUT
% Note OUT can be also save a a structure or an array as well)
end
0 comentarios
Ver también
Categorías
Más información sobre Event Functions 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!