% 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

1 件のコメント

Jan
Jan 2012 年 3 月 4 日
Please use a meaningful subject line and tags.

サインインしてコメントする。

 採用された回答

Titus Edelhofer
Titus Edelhofer 2012 年 3 月 4 日

0 投票

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

その他の回答 (1 件)

Jan
Jan 2012 年 3 月 4 日

0 投票

The error message is very clear: "Operands to and && operators must be convertible to logical scalar values." It is always worth to read the error messages of Matlab.

2 件のコメント

Nasir Qazi
Nasir Qazi 2012 年 3 月 5 日
it works with '&' instead of '&&'
Walter Roberson
Walter Roberson 2012 年 3 月 5 日
Nasir, it doesn't bomb out with an error if you change to &, but that doesn't mean that it works. Please review Titus's response and study the documentation for "any" and "all"

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by