Prev: Curve matching question
Next: Mark S whorton
From: David Young on 22 May 2010 07:18 Parker <xenoszh(a)gmail.com> wrote in message <c753e854-c76d-4f9e-b24b-8a50bf157035(a)y12g2000vbg.googlegroups.com>... > ... > always test equal like > > >> x1 = [1/3 repmat(2/3,1,10)]'; > >> x2 = [repmat(2/3,1,10) 1/3]'; > > >> if (mean(x1)-mean(x2))<eps > disp('Equal'); > else > disp('Unequal'); > end Not quite correct. Try the above with, for example, x2 = ones(size(x1)) and you'll find it will still report 'Equal'. What is needed is to take the absolute value of the difference: if abs(mean(x1)-mean(x2))<eps This is only correct if eps is the right tolerance. It often will be appropriate, but not always - it depends on the details of the computation that leads up to the test. |