comparevars

Compare any variables to detect difference in class, size and within a user defined tolerance
ダウンロード: 592
更新 2014/4/8

ライセンスの表示

Compare any variables to find differences, similar to isequal - but this function will tell you where the differences are in terms of the variable that differs and why.
Comparison can be done with tolerances (default 1e-8) to allow for precision changes.

Excellent for using while developing algorithms to check results before and after: e.g.

before = YourAlgorithm()
% change you code
after = YourAlgorithm();

comparevars ( before, after );

Funcion compares the two inputs (whether they are cells, structs, matrix, etc...) and tell you where any differences are.

Should work with any data class - if you find any that it does not work with please contact me with an example and I will update the code.

Also any feature requests - please let me know and I will try to build into the next release.

Extract from help below:

comparevars compare variables to within a given tolerance

Checks for variable comparison - returns true or false

flag = comparevars ( A, B )

flag = comparevars ( A, B, DCP, NaNCheck )
DCP : number of decimal places to check (1e-8 default)
NaNCheck : if true (default) NaNs are treated as being equal

entering [] in either DCP or NaNCheck will
result in the code using the defaults.

flag = comparevars ( A, B, DCP, NaNCheck, debug )

debug : flag to write check log to screen (default true)

see also isequal isequalwithequalnans test_comparevars

Example

% create a structure with lots of difference data types
A.data.level.x = [1 2 3];
A.data.level(2).x = [1 2 3];
A.data.level(2).func = str2func ( 'plot' );
A.data.cell = cell(20,1);
A.other.log.flag = true;
A.dummyData.integers.test = int8(1);
A.dummyData.char(20).example = 'ABCDeFGH';
A.dummyData.img =i;

% change value x
B = A;
B.data.level(2).x = zeros(3,2,4,3);
flag = comparevars ( A, B )

Check failed on size of variables not the same
A(1).data(1).level(2).x (1,3)
B(1).data(1).level(2).x (3,2,4,3)

ZIP file also contains an example mfile which performs example comparison.

引用

Robert Cumming (2024). comparevars (https://www.mathworks.com/matlabcentral/fileexchange/46165-comparevars), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2013b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersWorkspace Variables and MAT-Files についてさらに検索
謝辞

ヒントを与えたファイル: comparevars_inf

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.0.0.0