Pause Simulink simulation and wait for MATLAB to compute a new input before continuing.
3 次查看(过去 30 天)
显示 更早的评论
I would like to pause Simulink, get the ouput to MATLAB and once it's available, send a new input from MATLAB to Simulink and continue from the same state where it stopped. Do you think this is possible and how would you do it?
Extra info: At every clock cycle of a VHDL simulation in ModelSim, I would like to feed an output from ModelSim into Simulink as an input, and send Simulink's output back to ModelSim as an input, creating a closed loop. I am using MATLAB to estabilish a connection and send data to and from ModelSim.
0 个评论
回答(1 个)
Shubham
2024-9-20
编辑:Shubham
2024-9-20
Hey Martin,
You can indeed pause your simulation and establish an interaction between Simulink and MATLAB. Consider the following code snippet for pausing the Simulation and extracting the data from desired blocks:
model.set_param('model_name', 'SimulationCommand', 'pause');
output_data = get_param('model_name/BlockName', 'RuntimeObject').OutputPort(1).Data;
Once you have the required data, you may perform necessary computations on it in MATLAB. Finally, you may update the values in the Simulink model and continue with the simulation.
set_param('model_name/BlockName', 'Value', new_input_data);
set_param('model_name', 'SimulationCommand', 'continue');
In order to establish a communication between MATLAB and ModelSim, you may use MATLAB's external interfaces to communicate with ModelSim. For running the simulation for only a single time step, use the following command:
sim("ModelName",paramstruct);
% where paramstruct is a structure with field names that match each parameter name and field values that specify the value to use for each parameter.
You can learn more about the programmatic interactions between MATLAB and Simulink by referring to the following documentation: https://www.mathworks.com/help/simulink/ug/using-the-sim-command.html
I hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!