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

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

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 17 Set 2024
下記は、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')

Più risposte (0)

Categorie

Scopri di più su System Composer in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!