find and set simulink parameters for several blocks

11 ビュー (過去 30 日間)
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 10 月 17 日
回答済み: Orion 2014 年 10 月 17 日
I have a simulink model with number of subsystems. For example I have used simpower systems MOSFET in multiple places within my model.
At the moment I use the following code. But limitation is, that the bock paths/Names should be known.
for x=1:4 %debug_14.slx is the file name%
modd=sprintf('debug_14/HBridge/Mosfet%d',x);
set_param(modd,'Ron','3');
end
Now what if I have several Mosfet blocks, then it hard to specify the block path individually. I need to set Ron=3 for all Mosfets within my model. How can I programatically search mosfet blocks and set_param.

回答 (4 件)

Debarati Banerjee
Debarati Banerjee 2014 年 10 月 17 日
Regarding this question:
Find the attached sample model (‘trial_model.mdl’)where there are multiple ‘Gain’ blocks in the top model and also in subsystem. The path and names of all the ‘Gain’ blocks present in the model ‘trial_model’ can be found by the following command:
>>block_name = find_system('trial_model', 'BlockType', 'Gain')
Here block_name will be an n*1 cell array containing the names of all the ‘Gain’ blocks present in the model ‘trial_model.mdl’.
Then you can consider to run the following loop to change the parameters of each of the block. You can refer to the following sample code:
>> n=length(block_name)
for i=1:1:n
set_param(block_name{i,1},'Gain','15') %%Changing ‘Gain’ of all the ‘Gain’ blocks to 15
end
  1 件のコメント
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 10 月 17 日
The problem with MOSFET is it comes with sysmpower systems tool box. The block type appears to be a subsystem. Hence what should I specify for the keyword search for 'Blocktype'. Updated mdl file attached with MOSFETs in top level and subsystems.

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


Rashmil Dahanayake
Rashmil Dahanayake 2014 年 10 月 17 日
編集済み: Rashmil Dahanayake 2014 年 10 月 17 日
A temporary way around this. Works only if a Tag is specified under block properties.
trial_model;
cc=find_system('trial_model','Regexp', 'on','Tag', 'mo(.*)');
for x=1:length(cc)
block1=cc{x};
set_param(block1,'Ron','3');
end
limitation: Once off Tag set up for blocks required

Orion
Orion 2014 年 10 月 17 日
編集済み: Orion 2014 年 10 月 17 日
Hi,
try this
MyMosfetBlock = find_system('trial_model','SourceType','Mosfet')
specific property of your Mosfet block
then you use set_param to change the parameter you want.
  1 件のコメント
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 10 月 17 日
it returns an empty cell array. Which means the search criteria unable to locate mosfets.

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


Orion
Orion 2014 年 10 月 17 日
I tried
MyMosfetBlock = find_system('trial_model','SourceType','Mosfet')
with the mdl you attached, and I got the result
MyMosfetBlock =
'trial_model/Subsystem/sw1'
'trial_model/Subsystem/sw2'
'trial_model/sw1'
'trial_model/sw2'
i have Matlab 2014a, but this command line should work with every version.
Do you use Libraries, Masks ?

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by