モデルに事前に意図していないデータ型が含まれていないかを確認する方法はありますか?
3 views (last 30 days)
Show older comments
MathWorks Support Team
on 6 Sep 2019
Edited: MathWorks Support Team
on 24 Sep 2019
シミュレーションを実行するとデータ型の不一致でエラーが発生してしまいます。
事前に意図していないデータ型がモデルに含まれていないかを確認する方法を教えてください。
Accepted Answer
MathWorks Support Team
on 24 Sep 2019
Edited: MathWorks Support Team
on 24 Sep 2019
find_systemとget_paramコマンドによって実現できます。
find_systemコマンドによってモデルに含まれる全ブロックを見つけ、そのハンドルを取得します。
その後、取得したハンドルを元に各ブロックの出力ポートのデータ型をget_paramコマンドによって取得し、事前に取り決めたデータタイプと比較をすることでチェックします。
以下にスクリプト例を示します。
% strModel:モデル名
% cellDataType:事前に取り決めたデータタイプを有するセル配列 例. {'boolean', 'int8', 'uint16'}
% モデルのコンパイル
feval(strModel, [], [], [], 'compile');
% ブロックを見つける
hBlocks = find_system(strModel, 'FindAll', 'on', 'type', 'block');
% ブロックごとに出力ポートに設定されているデータ型を確認
count = 0;
for n = 1: numel(hBlocks)
h = hBlocks(n);
% 出力ポートの情報を取得
PH = get_param(h, 'PortHandles');
for k = 1: numel(PH.Outport)
hOut = PH.Outport(k);
% 指定したデータ型と一致するかを比較
strDataType = get_param(hOut, 'CompiledPortDataType');
if ~any(strcmp(cellDataType, strDataType))
count = count+1;
% コマンドウィンド上でクリックするとブロックへ移動できるようなハイパーリンクを使用
fprintf('%04d: <a href="matlab:hilite_system(''%s'')">%s</a>: %s\n', count, getfullname(h), getfullname(h), strDataType);
end
end
end
% コンパイルの解除
feval(strModel, [], [], [], 'term');
回答上部に添付されたファイルは、上記の内容を関数化したものです。
0 Comments
More Answers (0)
See Also
Categories
Find more on プログラムによるモデル編集 in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!