ブロック消去後のライ​ンをまとめて消去する​ことはできますか?

11 Ansichten (letzte 30 Tage)
MathWorks Support Team
MathWorks Support Team am 30 Aug. 2018
DELETE コマンドでブロックを消去することができますが、そのブロックに接続された線が残ってしまいます。これも含めて消去する方法を教えてください。

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 30 Aug. 2018
MATLAB/Simulink の標準関数にはこのような機能はありませんが、プログラミングにより実現することができますので、その方法をご紹介いたします。
■サンプルプログラム
(以下の2つの関数は両方とも sampleprog.m ファイルに保存します)
function sampleprog(sys)
% システム中の全ラインのハンドルを取得
lines = find_system( sys, ...
'LookUnderMasks', 'all', ...
'FindAll', 'on', ...
'Type', 'line' ) ;
% それぞれのラインで、ハンドルが存在する場合に削除関数を使用
for i=1:length( lines )
if ishandle( lines( i ) )
delete_unconnected( lines( i ) )
end
end
%削除関数の例
function delete_unconnected( line )
%'SrcPortHandle'がマイナスの場合、残ったラインと判断できる
if get( line, 'SrcPortHandle' ) < 0
delete_line( line ) ;
return
end
LineChildren = get( line, 'LineChildren' ) ;
%'DstPortHandle'がマイナスの場合、残ったラインと判断できる
if isempty( LineChildren )
if get( line, 'DstPortHandle' ) < 0
delete_line( line ) ;
end
else
for i=1:length( LineChildren )
delete_unconnected( LineChildren( i ) )
end
end
■実行手順
1) モデルを開く
>> f14
2) 適当なブロックを削除して、ラインを残す
3)以下で残ったラインを削除できます。
>> sampleprog('f14')

Weitere Antworten (0)

Kategorien

Mehr zu 関数 finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!