Simulink parameters change during simulation from Matlab cmd line
显示 更早的评论
I need to change the parametrs of the running Simulink simulation model from Matlab cmd line - I am not running the Simulink simulation programatically but just clicking on Simulation button (Ctrl+T) to run.
Is there simulation obeject available in workspace to set variable for this simulation?
采纳的回答
更多回答(1 个)
Walter Roberson
2025-7-9
编辑:Walter Roberson
2025-7-9
0 个投票
It is not possible to change the parametrs of the running Simulink simulation model from Matlab command line while the model is running . The model must be stopped (or perhaps pause()'d) . This is because Simulink runs in a different process.
... Though you could in theory set up udp receive blocks and send data to udp from the command line...
2 个评论
Paul
2025-7-9
What is the basis for this claim? It's counter to a very specific statement in the documentation (TBF, the documentation uses the term "during simulation" and not "while the simulation is running"), and also counter to actual experience, at least my experience.
It's hard to illustrate here in a scripting mode because scripted commands seem to behave differently than executing commands sequentially at the command line.
Here's the best I can do, hopefully it's convincing.
Define a simple model with a sine wave feeding a To Workspace block
bdclose('all');
hsys = new_system('updatetest');
hsine = add_block('simulink/Sources/Sine Wave','updatetest/Sine');
set_param(hsine,'Amplitude','A');
hout = add_block('simulink/Sinks/To Workspace','updatetest/output');
set_param(hout,'VariableName','y');
PH = 'PortHandles';
add_line(hsys, ...
get_param(hsine,PH).Outport,...
get_param(hout,PH).Inport);
Set infinite stop time and turn on pacing so that simulation run time equals wall clock time
set_param(hsys,'StopTime','inf','EnablePacing','on');
Initial value of amplitude
A = 1;
Start the simulation, pause Matlab for 5 seconds, and then stop the simulation.
set_param(hsys,SimulationCommand="start");
pause(5);
set_param(hsys,SimulationCommand="stop");
I think this figure illustrates that the simulation was running while the Matlab pause was in effect.
figure
plot(out.y)
Start the simulation and pause Matlab for five seconds. Simulation runs while Matlab is paused.
set_param(hsys,SimulationCommand="start");
pause(5);
Change the amplitude of the sine wave and update the diagram.
A = 10;
set_param(hsys,SimulationCommand="update");
Make sure the simulation runs for five more seconds.
pause(5);
set_param(hsys,SimulationCommand="stop");
Plot the output, show the effect of updating the parameter.
figure
plot(out.y)
类别
在 帮助中心 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




