このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。
この例では、モデル メトリクス API を使用して、モデルのサブシステムおよびブロックのカウントのメトリクスをプログラムにより収集する方法を説明します。モデルのメトリクスの収集後、結果にアクセスしてファイルにエクスポートできます。
Open model vdp.
model = 'vdp';
open_system(model);
モデルのメトリクス データを収集するには、メトリクス エンジン オブジェクトを作成して execute
を呼び出します。
metric_engine = slmetric.Engine(); setAnalysisRoot(metric_engine,'Root','vdp','RootType','Model'); execute(metric_engine);
Updating Model Advisor cache... Model Advisor cache updated. For new customizations, to update the cache, use the Advisor.Manager.refresh_customizations method.
getMetrics
メソッドを使用して、収集するメトリクスを指定します。この例では、vdp
モデルのブロックおよびサブシステムのカウントのメトリクスを指定します。getMetrics
は、slmetric.metric.ResultCollection
オブジェクトの配列を返します。
res_col = getMetrics(metric_engine,{'mathworks.metrics.SimulinkBlockCount',... 'mathworks.metrics.SubSystemCount'});
cell 配列 metricData
を作成し、メトリクス結果の MetricID
、ComponentPath
および Value
を格納します。MetricID
はメトリクスの識別子です。ComponentPath
はメトリクスが計算されたコンポーネントのパスです。また、Value
はメトリクス値です。結果を表示するループを記述します。
metricData ={'MetricID','ComponentPath','Value'}; cnt = 1; for n=1:length(res_col) if res_col(n).Status == 0 results = res_col(n).Results; for m=1:length(results) disp(['MetricID: ',results(m).MetricID]); disp([' ComponentPath: ',results(m).ComponentPath]); disp([' Value: ',num2str(results(m).Value)]); metricData{cnt+1,1} = results(m).MetricID; metricData{cnt+1,2} = results(m).ComponentPath; metricData{cnt+1,3} = results(m).Value; cnt = cnt + 1; end else disp(['No results for:',res_col(n).MetricID]); end disp(' '); end
MetricID: mathworks.metrics.SimulinkBlockCount
ComponentPath: vdp
Value: 13
MetricID: mathworks.metrics.SimulinkBlockCount
ComponentPath: vdp/More Info
Value: 1
MetricID: mathworks.metrics.SimulinkBlockCount
ComponentPath: vdp/More Info/Model Info
Value: 1
MetricID: mathworks.metrics.SimulinkBlockCount
ComponentPath: vdp/More Info/Model Info/EmptySubsystem
Value: 0
MetricID: mathworks.metrics.SubSystemCount
ComponentPath: vdp
Value: 1
MetricID: mathworks.metrics.SubSystemCount
ComponentPath: vdp/More Info
Value: 0
MetricID: mathworks.metrics.SubSystemCount
ComponentPath: vdp/More Info/Model Info
Value: 1
MetricID: mathworks.metrics.SubSystemCount
ComponentPath: vdp/More Info/Model Info/EmptySubsystem
Value: 0
metricData
の結果、MetricID
、ComponentPath
および Value
をスプレッドシートにエクスポートするには、writetable
を使用して metricData
の内容を MySpreadsheet.xlsx
に書き込みます。
filename = 'MySpreadsheet.xlsx';
T=table(metricData);
writetable(T,filename);
メトリクス結果を XML ファイルにエクスポートするには、exportMetrics
メソッドを使用します。各メトリクス結果について、XML ファイルには ComponentID
、ComponentPath
、MetricID
、Value
、AggregatedValue
および Measure
が含まれます。
filename='MyMetricResults.xml';
exportMetrics(metric_engine,filename)
モデル vdp
を閉じます。
bdclose(model);
1 つのモデルに関して、複数のプラットフォーム上の同じデータベース ファイル (Metrics.db
ファイル) にメトリクス データを収集することはできません。
slmetric.Engine
| slmetric.metric.Result
| slmetric.metric.ResultCollection