set_param() - programmatically change param of multiple blocks of the same type (for-loop)

13 ビュー (過去 30 日間)
Hi everyone!
Suppose there are 50 blocks of the same type in a simulink/simscape model - let's say it is a pipe-block in simscape domain.
Is there any recipe to change a specific parameter of all blocks programmatically?
I have a solution, but it assumes that the bocks of the same type are named with a consecutive number like this: pipe_1, pipe_2.
for iter_pipes = 1:50
set_param(...
model_name + "/pipe_" + string(iter_pipes),...
"p_I_specify","on",...
"p_I_priority","High",...
"p_I","550000"...
)
end
Is there any way to access a specific param of multiple blocks of the same type regardless of the blocks name?
Thank you in advance for any help!
Michael

採用された回答

Jesús Zambrano
Jesús Zambrano 2021 年 8 月 10 日
That´s a good solution. For any other case, you might try to first use the command find_system, to then look for the blocks you want to change.
The following link has some examples of how to use this command:
  2 件のコメント
Michael Feichtinger
Michael Feichtinger 2021 年 8 月 11 日
編集済み: Michael Feichtinger 2021 年 8 月 11 日
Thx Jeúsus for the quick response.
Got a second solution, which takes a str. for searchin' specific blocks.
In my case it is more appropriate solution, cause i have to handle with pipenames like pipe_12_a, pipe_12_b....
model_name = "SIM_X";
all_simscape_blocks = find_system(model_name);
simscape_blocks_pipes_idx = startsWith(all_simscape_blocks,"SIM_X/pipe");
simscape_blocks_pipes = all_simscape_blocks(simscape_blocks_pipes_idx);
for i = 1:length(simscape_blocks_pipes)
set_param(...
simscape_blocks_pipes(i),...
"p_I_specify","on",...
"p_I_priority","High",...
"p_I","550000"...
)
end
Jesús Zambrano
Jesús Zambrano 2021 年 8 月 11 日
Great to see it worked! Thanks for sharing!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFoundation and Custom Domains についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by