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에서 Simulink Environment Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




