set_param() in Repeating Sequence / Simulink doesn't work

조회 수: 3 (최근 30일)
Ronron
Ronron 2015년 6월 5일
댓글: Drew Davis 2015년 6월 9일
Hello, Today I tried to change the y-Parameter of a repeating-Sequence-Block during Simulation.
rs_y1 = 0:200;
set_param('RS_test/rs','rep_seq_y','rs_y1');
I defined rs_y1 as global variable. The strange thing is that I don't get any errors or warnings (I can even see that the little graph on the repeating-Sequence-block changes). Can someone explain why the new y-Parameters aren't used during the simulation? And maybe there is a solution?

채택된 답변

Drew Davis
Drew Davis 2015년 6월 8일
Variables in the workspace are initialized once during model update before the simulation runs. Therefore, a change in value of the variable in the workspace will not reflect a change in value of the block parameter during simulation.
You can however change the value of the parameter directly by assigning the value of the workspace variable to the block with the following command:
set_param(gcb , 'rep_seq_y' , ['[' num2str(a) ']'])
Where 'a' is some row vector.
Alternatively, after you change the workspace variable, you can force a model update to ensure any changes in workspace variables are reflected in the model during simulation:
set_param(bdroot , 'SimulationCommand', 'update')

추가 답변 (1개)

Ronron
Ronron 2015년 6월 9일
Why is that transformation str2num(a) required, as my vector a is numeral? But thanks, it worked like that!
  댓글 수: 1
Drew Davis
Drew Davis 2015년 6월 9일
For edit fields inside a block mask, text entries are interpreted as strings

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by