Possible Duplicate:
Octave/MATLAB: How to compare structs for equality?
is there a simple comparison function for matlab cell or struct objects? using '==' doesn't seem to work :(
Possible Duplicate:
Octave/MATLAB: How to compare structs for equality?
is there a simple comparison function for matlab cell or struct objects? using '==' doesn't seem to work :(
If you want to know if two cell arrays or struct objects are exactly equal you could always use isequaln.
Use isequal
to compare two cells. Note however that ==
is not advised even for arrays:
>> A = [1 2 3 4 5];
>> B = [1 2 3 4 5];
>> A == B
ans =
1 1 1 1 1
You would need to use a further trick to use that expression in a if statement for instance.
The reason ==
is not recommended for variables of type double
is because of the IEEE 754 representation use by MATLAB. For instance:
>> .1 + .1 + .1 == .3
ans =
0
To compare double values more robustly, you can use the abs
function in MATLAB:
>> if ( abs( (.1+.1+.1) - .3 ) < 1e-10 ); disp('Values are pretty close although not necessarily bit equal'); end
Values are pretty close although not necessarily bit equal
>>