I'm using matlab and want to check whether a column vector is equal to another withing 3dp, to do this i'm trying to create an array full of 0.001 and checking whether it is greater than or equal. is there a simpler way than a for loop to create this array or no?
4 Answers
You may consider the 'find' command, like:
a = [ 0.005, -0.003 ];
x = find(a > 0.001);
FWIW, I've found comparing numbers in MATLAB to be an absolute nightmare, but I am also only new to it. The point is, you may have floating-point comparision issues when do you the compares, so keep this in mind when attempting anything (and someone please correct me if I'm wrong on this or there is a beautiful workaround.)
2 Comments
rwong
To deal with comparison issues, you can use
eps. In general, floating-point comparison affects all languages, not just MATLAB. You can read some materials on numerical methods because the numerical errors may accumulate after a large number of operations. For example, in some cases it is sqrt(eps).Noon Silk
@wrong: Sure, I know about
eps, and I know about floating point comparisions, but eps doesn't always help. Thanks though.