複数の Interpolation Using Prelookup ブロックのマージによるコードの効率性の改善
モデル トランスフォーマー ツールを使用すると、モデル化パターンをリファクタリングして、生成コードの効率性を改善できます。モデル トランスフォーマーは、Prelookup ブロックの出力から単一の Interpolation Using Prelookup ブロックに接続されている同じ入力信号を持つ複数の Interpolation Using Prelookup ブロックを特定し、マージします。
モデル トランスフォーマーは、Interpolation Using Prelookup ブロックの [テーブル データ] 以外のプロパティが同じ場合に機能します。モデル内の Interpolation Using Prelookup ブロックの数を削減することで、コード内の変数割り当ての数が削減され、生成されたコードの効率性が向上します。モデル トランスフォーマー アプリまたはプログラムのコマンドを使用して、モデルをリファクタリングできます。
モデル トランスフォーマーは、次のような複数の Interpolation Using Prelookup を置き換えることができます。
同じインデックスおよび小数部パラメーターを持つ Prelookup ブロックに接続されている同じ入力信号がある
同じ Multiport Switch ブロックに接続された出力信号がある
同じブレークポイントの指定、値、データ型がある
同じアルゴリズム パラメーターがある
小数部パラメーターに対して同じデータ型がある
モデル トランスフォーマー アプリを使用した Interpolation Using Prelookup ブロックのマージ
この例では、モデル トランスフォーマーを使用して冗長な Interpolation Using Prelookup ブロックを特定し、モデルをリファクタリングする方法を説明します。

モデル ex_interpolation_optimize は Prelookup ブロックを使用して信号を複数の Interpolation Using Prelookup ブロックに入力します。こうした Interpolation ブロックの出力が Multiport Switch ブロックに接続されています。
この例では、変換の条件を満たす Interpolation Using Prelookup ブロックを特定し、それらを 1 つの Interpolation Using Prelookup ブロックと、Multiport Switch ブロックに接続された Constant ブロックに置き換えます。
モデルを作業フォルダーに保存します。
[アプリ] タブで、[モデル トランスフォーマー] をクリックします。
[変換] フォルダーで、Replace Interpolation Using Prelookup Blocksチェックを選択します。
[この変換で、ライブラリ内の Interpolation-ND ブロックをスキップします。] オプションを選択して、ライブラリにリンクされている Interpolation Using Prelookup ブロックが置換されないようにします。
[変換後のモデル名の接頭辞] フィールドで、リファクタリングされたモデルの接頭辞を指定します。
[このチェックを実行] をクリックします。上部の [結果] テーブルには、Interpolation Using Prelookup ブロックと、それに対応する Multiport Switch ブロックの端子インデックスへのハイパーリンクが含まれています。
変換しないグループの [Candidate Groups] の下にあるチェック ボックスをオフにします。
[モデルのリファクタリング] をクリックします。[結果] テーブルには、新しいモデルへのハイパーリンクが含まれています。テーブルには、共有 Interpolation Using Prelookup ブロックと、それに対応する Multiport Switch ブロック端子へのハイパーリンクが含まれています。ツールによって、新しい
gen_ex_interpolation_optimize.slxモデルを含むm2m_ex_interpolation_optimizeフォルダーも作成されます。

gen_ex_interpolation_optimize.slx モデルにある 2 つの Prelookup ブロック Prelookup および Prelookup1 が単一の Interpolation Using Prelookup ブロックに接続され、Constant ブロックは Multiport Switch ブロック端子に接続されて [テーブル データ] を入力として提供します。

プログラムによる Interpolation Using Prelookup ブロックのマージ
モデル トランスフォーマーをプログラムによって使用するには、以下のようにします。
Simulink.ModelTransform.CommonSourceInterpolation.identifyCandidatesを使用して、変換の候補を特定するSimulink.ModelTransform.CommonSourceInterpolation.refactorModelを使用して、モデルをリファクタリングする
モデル
ex_interpolation_optimizeを現在の作業ディレクトリに保存します。変換の条件を満たす候補を特定するには、関数
Simulink.ModelTransform.CommonSourceInterpolation.identifyCandidatesを使用してオブジェクトtransformResultsを作成します。transformResults = Simulink.ModelTransform.CommonSourceInterpolation.identifyCandidates('ex_interpolation_optimize')transformResults = Results with properties: Candidates: [1×1 struct]transformResultsオブジェクトには 1 つのプロパティCandidatesがあります。これは、InterpolationPortsとSwitchPortsの 2 つのフィールドをもつ構造体です。transformResults.Candidates = struct with fields: InterpolationPorts: [4×1 struct] SwitchPorts: [4×1 struct]InterpolationPortsフィールドを表示します。transformResults.Candidates.InterpolationPorts =
4×1 struct array with fields: Block PortInterpolationPortsフィールドは 2 つの配列BlockとPortで構成されます。同様に、SwitchPortsには同じプロパティがあります。Candidates.InterpolationPortsフィールドとCandidates.SwitchPortsフィールドをテーブルに変換します。struct2table(transformResults.Candidates.InterpolationPorts) struct2table(transformResults.Candidates.SwitchPorts)
ans = 4×2 table Block Port _____________________________________________ ____ {'ex_interpolation_optimize/Interpolation↵Using Prelookup' } 0 {'ex_interpolation_optimize/Interpolation↵Using Prelookup1'} 0 {'ex_interpolation_optimize/Interpolation↵Using Prelookup2'} 0 {'ex_interpolation_optimize/Interpolation↵Using Prelookup3'} 0 ans = 4×2 table Block Port ______________________________ ____ {'ex_interpolation_optimize/Multiport_Switch'} 1 {'ex_interpolation_optimize/Multiport_Switch'} 2 {'ex_interpolation_optimize/Multiport_Switch'} 3 {'ex_interpolation_optimize/Multiport_Switch'} 4SwitchPortsを使用して、どの Interpolation Using Prelookup ブロックがどの Multiport Switch ブロック端子に接続されているか確認します。モデルをリファクタリングするには、関数
Simulink.ModelTransform.CommonSourceInterpolation.refactorModelを使用します。この関数は、関数identifyCandidateからのtransformResultsオブジェクトを使用します。refactorResults = Simulink.ModelTransform.CommonSourceInterpolation.refactorModel(transformResults)
refactorResults = RefactorResults with properties: ModelName: 'ex_interpolation_optimize' ModelDirectory: '' TraceabilityInfo: [4×1 containers.Map]refactorResultsオブジェクトのModelNameプロパティとModelDirectoryプロパティは参照モデルの名前と場所をリストします。TraceabilityInfoはブロックのトレース情報をリストするcontainers.Mapオブジェクトです。
条件と制限
モデル トランスフォーマーは、次の場合は Interpolation Using Prelookup ブロックを置換できません。
Interpolation Using Prelookup ブロックがコメントアウトされた領域にあるか、非アクティブなバリアントである。
Interpolation Using Prelookup ブロックがマスクされている。
モデル トランスフォーマー アプリでは、Atomic サブシステム、参照モデル、またはライブラリにリンクされたブロックの境界を越える Interpolation Using Prelookup ブロックの置換は行われません。