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

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

 Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 17 Sep 2024

0 votes

下記は、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')

Plus de réponses (0)

Catégories

En savoir plus sur System Composer dans Centre d'aide et File Exchange

Produits

Version

R2023b

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!