How to get_param list on subsystem blocks inport and outports

Hi Guys,
I am trying how to figure out how to generate a list of a subsystems inports and outport names. This should be a list of the names that are listed on the block, not what is connected to it. I have been trying various things, and the closest I can get is to have get_param tell me how many inputs and how many output ports there are, but no signal names.
Thanks for the help.

3 件のコメント

Kaustubha Govind
Kaustubha Govind 2013 年 8 月 15 日
Do you mean the port labels on the subsystems? Are these masked subsystems (in which case the port labels are specified on the Mask) or un-masked subsystems, where the ports labels are inferred from the names of the top-level inport and outport blocks.
Michael
Michael 2013 年 8 月 16 日
Example: I want a command that will give me "Position" "Velocity" and "Accel" (the inport names) and a command that gives me "Voltage" (the outport name). Assuming that I am using the default "Subsystem" block in simulink.
Bharath
Bharath 2025 年 4 月 29 日
編集済み: Bharath 2025 年 4 月 29 日
open_system('task'); % Open the model
% Find only top-level Inport and Outport blocks
Inports = find_system('task', 'BlockType', 'Inport');
Outports = find_system('task','BlockType', 'Outport');
% Initialize output cell arrays
In = {};
Out = {};
% Process Inports
for j = 1:lengthInports)
% [~, name] = strtok(topInports{j}, '/'); % Remove model name
In{j} = name(2:end); % remove the initial slash
end
% Process Outports
for k = 1:length(Outports)
% [~, name] = strtok(topOutports{k}, '/');
Out{k} = name(2:end);
end
% Display results
disp(' Inports:');
disp(In);
disp(' Outports:');
disp(Out);

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

回答 (3 件)

Purshottam Vishwakarma
Purshottam Vishwakarma 2018 年 4 月 6 日

5 投票

simBlockH = get_param(gcb, 'Handle');
handles = find_system(simBlockH, 'LookUnderMasks', 'on', 'FollowLinks', 'on', 'SearchDepth', 1, 'BlockType', 'Inport');
portNames = cellstr(get_param(handles, 'Name'))

1 件のコメント

Dipesh007
Dipesh007 2020 年 5 月 21 日
Hello Purshottam,
Thanks for the solution it help me.
Now how can i export these Inport from command window to xls using mscript.
Thanks in advance.

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

Chetan Aswathanarayana
Chetan Aswathanarayana 2013 年 8 月 18 日

2 投票

You can try the below: Say your Model is Sample.mdl:
open_system('Sample');
blks = find_system('Sample','Type','block');
N = get_param(blks, 'BlockType');
j = 1;
k = 1;
for i = 1:length(N)
if ( strcmp(N{i},'Inport'))
In{j} = blks{i};
In{j} = strrep(In{j},'Sample/Subsystem/',[]);
j = j + 1;
elseif ( strcmp(N{i}, 'Outport'))
Out{k} = blks{i};
Out{k} = strrep(Out{k},'Sample/Subsystem/',[]);
k = k + 1;
end
end
In and Out are the 2 ouput cell arrays, which gives what you are looking for:
>> In
In =
'Position' 'Velocity' 'Accel'
>> Out
Out =
'Voltage'

4 件のコメント

Miriam
Miriam 2013 年 9 月 2 日
I have the same problem, but the solution isn't working. N is just a 1x1 cell containig the string SubSystem.
Is there something wrong with my subsystem?
Miriam
Miriam 2013 年 9 月 2 日
Ah, I see, I have to allow him to look under the mask :D
vvd03
vvd03 2015 年 2 月 20 日
編集済み: vvd03 2015 年 2 月 20 日
Hello! How realise it for masked subsystem? I see that it work for unmasked subsystem. How to allow him to look under the mask?
vvd03
vvd03 2015 年 2 月 21 日
Oh! Sorry! I need this command:
... = find_system(...,'LookUnderMasks','all',...)

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

Chetan Aswathanarayana
Chetan Aswathanarayana 2013 年 8 月 16 日

0 投票

Hi Michael, If I understand your question correctly , you are looking to get the Input and Output Signal names.Then you can try the below:
>>model = 'Sample';
>>blks = find_system(model,'Type','block')
blks =
'Sample/In1'
'Sample/Unit Delay'
'Sample/Out1'
>>N = get_param(blks, 'BlockType')
istblks =
'Inport'
'UnitDelay'
'Outport'
The above gives the names for the list of all the blocks. And 'N' tells you which of the blocks are inports and outports.

1 件のコメント

Michael
Michael 2013 年 8 月 16 日
Example: I want a command that will give me "Position" "Velocity" and "Accel" (the inport names) and a command that gives me "Voltage" (the outport name). Assuming that I am using the default "Subsystem" block in simulink.

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

カテゴリ

ヘルプ センター および File ExchangeProgrammatic Model Editing についてさらに検索

製品

質問済み:

2013 年 8 月 15 日

編集済み:

2025 年 4 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by