MATLAB: Help with plz

&& with arrays

% Note :- in this code y & x has 10 values, but every time I run % the command it will give me this error… %*(??? Operands to the and && operators must be convertible to logical scalar values.)*
Error in ==> dewpointT at 75 if (abs(raw(1)) < 1e-5 && abs((y./K)-x) < 1e-5)
raw(1)= sum(y./K)-1;
if (abs(raw(1)) < 1e-5 && abs((y./K)-x) < 1e-5)
break

Best Answer

Hi,
if y and x are vectors, then abs((y./K)-x)<1e-5) is a (logical) vector as well. You will need to decide, if the relation must hold for at least one index, or for all of them. Replace by
any(abs((y./K)-x)<1e-5))
or
all(abs((y./K)-x)<1e-5) )
accordingly.
Titus
Related Question