Simulink parameters change during simulation from Matlab cmd line
Show older comments
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?
Accepted Answer
More Answers (1)
Walter Roberson
on 9 Jul 2025
Edited: Walter Roberson
on 9 Jul 2025
0 votes
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 Comments
Paul
on 9 Jul 2025
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)
Categories
Find more on Simulink Environment Customization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



