MATLAB: Visdiff, Can you include a tolerance

compare valuesMATLABtolerancevisdiff

I'm trying to use visdiff to compare the output of two versions of a software, and make sure that the changes I made are not altering the result. I've saved the outputs to a .mat file and have several different .mat files which I would like to compare to their corresponding previous versions.
The problem is visdiff will return variables not matching even if they are very close. I would like to find some way to compare the two files, while allowing for a tolerance. For instance, the following two numbers are pulled from corresponding .mat files from the two versions, and visdiff says they're "different"
Old Version: 84.972465581755998 New Version: 84.972465581758897
My application is not concerned with how well these match at the 12th decimal point.
Thanks for any help!
JR

Best Answer

isclose = @(x,y)isequal(size(x),size(y))&&all(abs(x(:)-y(:))<10^-10)
isclose(84.97246558175599,84.972465581758897)
Edit Per Comments
x = magic(3); %sample data
y = rand(10,1);
z = 'hello world';
save('ans427.mat','x','y','z') %save it twice
save('ans4272.mat','x','y','z')
S1 = importdata('ans427.mat'); %load the stuff
S2 = importdata('ans4272.mat');
fns1 = fieldnames(S1); %get fields.
fns2 = fieldnames(S2);
for ii = 1:length(fns1) %compare every field
bool = isclose(S1.(fns1{ii}),S2.(fns2{ii}));
if ~bool
break
end
end
obviously you add more checks to make this faster: are there the same number of field names? do the field names have to be the same?
This is just a simple example.
Related Question