setting Simulink data view tolerance progamatically

3 ビュー (過去 30 日間)
Albert Mathews
Albert Mathews 2015 年 6 月 1 日
回答済み: William R 2018 年 8 月 24 日
is it possible to to set the tolerance used by the SDI programatically? for example,assuming i have some .mat files called alldata_b, and alldata from separate simulink runs.
runID5 = Simulink.sdi.createRun('alldata_b','file','alldata_b');
runID6 = Simulink.sdi.createRun('alldata', 'file','alldata');
diffSDI_tmp = Simulink.sdi.compareRuns(runID5, runID6);
% Number of comparisons in result
cntSigCmp_tmp = diffSDI_tmp.count;
% Iterate through each result element
for i = 1:cntSigCmp_tmp
% Get signal result at index i
sigDiff_tmp = diffSDI_tmp.getResultByIndex(i);
sigNam_tmp = Simulink.sdi.getSignal(i); % create the object first
sigNam_tmp = sigNam_tmp.signalLabel; % get the object from the object
sigDiff_tmp.tol = 1;
end
the line "sigDiff_tmp.tol = 1;" gives the following result:
You cannot set the read-only property 'tol' of DiffSignalResult.
Error in <my_script> (line X)
sigDiff_tmp.tol = 1;
does this mean the only way to change the tolerance is by editing in the SDI? is there no way around this?

採用された回答

Sriram Narayanan
Sriram Narayanan 2015 年 6 月 3 日
It is currently not possible to tune the signal comparison tolerance programmatically. However, one could specify the absolute and relative tolerance for each signal programmatically.
The following is a code snippet of how this can be achieved.
% Configure model "slexAircraftExample" for logging and simulate
simOut = sim('slexAircraftExample', 'SaveOutput','on', ...
'SaveFormat', 'StructureWithTime', ...
'ReturnWorkspaceOutputs', 'on');
% Create a Simulation Data Inspector run
[runID,runIndex,signalIDs] = Simulink.sdi.createRun('My Run', ...
'base',{'simOut'});
% Get the Simulink.sdi.Run object corresponding to the new run ID
runObj = Simulink.sdi.getRun(runID);
% Get the number of signals in the run
numSignals = runObj.signalCount;
% Get the Simulink.sdi.Signal objects for each signal in the run
% Specify the absolute and relative tolerance for each signal
for i = 1:numSignals
signalObjs(i) = runObj.getSignal(signalIDs(i));
signalObjs(i).absTol = 0.5;
signalObjs(i).relTol = 0.005;
end
  1 件のコメント
Albert Mathews
Albert Mathews 2015 年 6 月 23 日
Thank you Sriram Narayanan The answer above works for setting the tol values for a run. however, an additional note should be made that if the user wants to set the tol values for a SDI.compareRuns object, the tol values MUST be set for the first run argument, see below, otherwise setting tols for the second run argument does nothing.
runID1 = Simulink.sdi.createRun(blah blah);
[runID,runIndex,signalIDs] = Simulink.sdi.createRun(blah blah);
% Get the Simulink.sdi.Run object corresponding to the new run ID
runObj = Simulink.sdi.getRun(runID);
% Get the number of signals in the run
numSignals = runObj.signalCount;
% Get the Simulink.sdi.Signal objects for each signal in the run
% Specify the absolute and relative tolerance for each signal
for i = 1:numSignals;
signalObjs(i) = runObj.getSignal(signalIDs(i));
signalObjs(i).absTol = 1;
signalObjs(i).relTol = 0.1;
end
diffSDI_tmp = Simulink.sdi.compareRuns(runID, runID1, Simulink.sdi.AlignType.BlockPath);
note how the tols are set for runID, and NOT runID1. and how runID is the first run argument in Simulink.sdi.compareRuns

サインインしてコメントする。

その他の回答 (1 件)

William R
William R 2018 年 8 月 24 日
But what is not answered in this post is how to set the time tolerance programmatically of a signal. This can be done manually in the SDi but if you store a Simulink.sdi.Signal to the workspace there is no timeTol property and you can also not add or edit this. If you try to add it the following error pops up:
No public property TimeTol exists for class Simulink.sdi.Signal.
Why is this not possible? Or is there another way to do this?

カテゴリ

Help Center および File ExchangeAnalyze Simulation Results についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by