メインコンテンツ

slreportgen.utils.sortObjects

Simulink オブジェクトの並べ替え

R2022b 以降

説明

sortedList = slreportgen.utils.sortObjects(objectList) は、objectList 内の要素を名前のアルファベット順に並べ替えます。関数 sortObjects を使用する前に、オブジェクトを含むモデルを読み込んでおく必要があります。関数は、無効な要素を無視して除外します。

sortedList = slreportgen.utils.sortObjects(objectList,sortMethod) は、sortMethod を使用して objectList 内の要素を並べ替えます。

すべて折りたたむ

この例では、関数 slreportgen.utils.sortObjects を使用して Simulink オブジェクトを深さ順に並べ替える方法を説明します。

長い完全修飾関数名およびクラス名を使用せずに済むよう、次の名前空間をインポートします。

import slreportgen.finder.*
import slreportgen.utils.*

Simulink モデル sortByDepthExampleModel を読み込みます。

model_name = "sortByDepthExampleModel";
load_system(model_name)

slreportgen.finder.DiagramFinder オブジェクトを使用して、モデル内のすべてのシステム (モデル自体を含む) を検索します。次に、空の配列 slreportgen.finder.BlockResult を作成します。

sysArray = find(DiagramFinder(model_name));
unsortedList = BlockResult.empty;

sysArray を反復処理し、slreportgen.finder.BlockFinder オブジェクトを使用して各サブシステム内のブロックを検索します。各サブシステムについて、検索結果ブロック配列を配列 unsortedList の末尾に追加します。

for idx = 1:length(sysArray)
  curBlockFinder = BlockFinder(sysArray(idx));
  curBlockFinder.BlockTypes = ["Inport","Gain","Outport"];
  curSysBlocks = find(curBlockFinder);
  unsortedList(end+1:end+length(curSysBlocks)) = curSysBlocks;
end

unsortedList 内のブロックのパスを表示して、それらのパスがどのように並べ替えられるかを確認します。

disp([unsortedList.BlockPath]');
    "sortByDepthExampleModel/In0"
    "sortByDepthExampleModel/Gain0"
    "sortByDepthExampleModel/Out0"
    "sortByDepthExampleModel/Sub1/In1"
    "sortByDepthExampleModel/Sub1/Gain1"
    "sortByDepthExampleModel/Sub1/Out1"
    "sortByDepthExampleModel/Sub1/Sub3/In3"
    "sortByDepthExampleModel/Sub1/Sub3/Gain3"
    "sortByDepthExampleModel/Sub1/Sub3/Out3"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/In4"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/Gain4"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/Out4"
    "sortByDepthExampleModel/Sub1/Sub5/In5"
    "sortByDepthExampleModel/Sub1/Sub5/Gain5"
    "sortByDepthExampleModel/Sub1/Sub5/Out5"
    "sortByDepthExampleModel/Sub2/In2"
    "sortByDepthExampleModel/Sub2/Gain2"
    "sortByDepthExampleModel/Sub2/Out2"

関数 slreportgen.utils.sortObjects を使用して、unsortedList 内のブロックを深さ順に並べ替えます。次に、並べ替えられたブロックのパスを表示して、それらのパスが深さ順に並べ替えられていることを確認します。

sortedList = sortObjects(unsortedList,"depth");
disp([sortedList.BlockPath]');
    "sortByDepthExampleModel/In0"
    "sortByDepthExampleModel/Gain0"
    "sortByDepthExampleModel/Out0"
    "sortByDepthExampleModel/Sub1/In1"
    "sortByDepthExampleModel/Sub1/Gain1"
    "sortByDepthExampleModel/Sub1/Out1"
    "sortByDepthExampleModel/Sub2/In2"
    "sortByDepthExampleModel/Sub2/Gain2"
    "sortByDepthExampleModel/Sub2/Out2"
    "sortByDepthExampleModel/Sub1/Sub3/In3"
    "sortByDepthExampleModel/Sub1/Sub3/Gain3"
    "sortByDepthExampleModel/Sub1/Sub3/Out3"
    "sortByDepthExampleModel/Sub1/Sub5/In5"
    "sortByDepthExampleModel/Sub1/Sub5/Gain5"
    "sortByDepthExampleModel/Sub1/Sub5/Out5"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/In4"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/Gain4"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/Out4"

入力引数

すべて折りたたむ

並べ替える Simulink® オブジェクトのリスト。次の値のいずれかとして指定します。

例: slreportgen.utils.sortObjects(["f14","f14/Actuator Model","f14/Aircraft Dynamics Model","sf_car"])

例: slreportgen.utils.sortObjects(find_system("f14",findall=true))

例: slreportgen.utils.sortObjects([find(slreportgen.finder.BlockFinder("sf_car")),find(slreportgen.finder.SignalFinder("sldemo_fuelsys"))])

並べ替えメソッド。次の値のいずれかとして指定します。

  • "alphabetical" — オブジェクトを名前のアルファベット順に並べ替える。

  • "systemAlpha" — オブジェクトを親システム名のアルファベット順に並べ替える。

  • "depth" — オブジェクトをモデルの階層構造の深さ順に並べ替えて、親サブシステムが子サブシステムの前に表示されるようにする。例については、Simulink® オブジェクトを深さ順に並べ替えを参照してください。

出力引数

すべて折りたたむ

並べ替えられたリスト。string 配列、ハンドル配列、または検索結果オブジェクト配列として返されます。返される配列のタイプは objectList と同じになります。

バージョン履歴

R2022b で導入