コマンドで、System Composerのコ​ンポーネント(Com​ponent)のポー​ト名を取得し、変更す​る方法はありますか?

コマンドを使って、System Composerのコンポーネント(Component)のポート名を取得し、変更したいです。

 采纳的回答

0 个投票

下記は、InBus/OutBusポートとConn(物理ポート)の例になります。
​
1)InBus/OutBusポート
​
%モデルを開く
open_system('test')
​
%'test/Component'のInportとOutportを検索
inports = Simulink.findBlocksOfType('test/Component', 'Inport');
Outports = Simulink.findBlocksOfType('test/Component', 'Outport');
​
%Inportの名前を変更
name = get_param(inports(1), 'PortName')
set_param(inports(1), 'PortName','AA')
​
%Outportの名前を変更
name = get_param(Outports(1), 'PortName')
set_param(Outports(1), 'PortName','BB')
​
​
2)Conn(物理ポート)
​
%モデルを開く
open_system('test')
​
% 指定したコンポーネント内のPMIOPortブロックを検索
phyPorts = Simulink.findBlocksOfType( 'test/Component1', 'PMIOPort');
​
% 各ブロックのポート名を取得
portNames = cell(length(phyPorts), 1); % セル配列を初期化
for i = 1:length(phyPorts)
  % ブロックのポート名を取得
  portNames{i} = get_param(phyPorts(i), 'Name'); % 丸かっこ()でインデックス
end
​
% 結果を表示
disp(portNames);
​
%ポート名を変更する場合、portNamesのインデックス指定で行う必要があります。
​
set_param(phyPorts(1), 'Name','port_1')
set_param(phyPorts(2), 'Name','port_2')

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 System Composer 的更多信息

产品

版本

R2023b

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!