Using set_param for multiple variables.
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to update 20 variables in a Simulink model by using set_param in an m script file. Is there any way to do this using a "for i=1:20" subroutine referencing Constant1, Constant2, Constant3, etc, as Constant(i) and with data from Q(i), so I do not have to write 20 separate entries in the set_param command?
댓글 수: 0
채택된 답변
Sebastian Castro
2015년 11월 4일
편집: Sebastian Castro
2015년 11월 4일
Sure. sprintf is handy here.
for idx = 1:20
blockName = sprintf('myModel/Constant%i',idx);
blockValue = sprintf('Q(%i)',idx);
set_param(blockName,'Value',blockValue);
end
You can also use the num2str function if that works better.
set_param(blockName,'Value',num2str(Q(idx));
- Sebastian
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!