Only else part is being executed in If-else statement in matlab -
i'm working on counting numbers using if-else
statement. i'm getting result, it's executing else part , not looking @ other part.
this code i'm working with
i = 0; j = 0; if sum( abs( f1(:) - f2(:))) == 0.0 = + 1; else j = j + 1; end if sum(abs(f2(:) - f3(:))) == 0.0 = + 1; else j = j + 1; end if sum(abs(f3(:) - f4(:))) == 0.0 = + 1; else j = j + 1; end msgtext = sprintf('matching = %d',i); h = msgbox(msgtext); msgtxt = sprintf(' not matching = %d',j); h = msgbox(msgtxt);
any suggestions?
thanks in advance!
your question extremely vague i'm going pretend asked 1 of if
s:
if sum( abs( f1(:) - f2(:))) == 0.0 = + 1; else j = j + 1; end
i think there fair chance ever fall else
clause because trying equate floating point numbers, , bad idea due precision errors. depends on nature of f1
, f2
, doubles, how calculated etc have given no indication of in question. if want understand why can't equate floating point numbers (or expect there difference equal 0
) must read what every computer scientist needs know floating-point arithmetic
rather try if sum( abs( f1(:) - f2(:))) < tol
tol
(i.e. tolerance) tiny number (e.g. eps
, choose number orders of magnitude less application produce.).
Comments
Post a Comment