operands to the and && operators must be convertible to logical scalar

1 回表示 (過去 30 日間)
Hana
Hana 2014 年 8 月 5 日
コメント済み: Michael Haderlein 2014 年 8 月 7 日
why do I get this error? I used single & also,but got the same error.
for ind_x = 1:1000
for ind_y =1:800
[ind_x,ind_y] =find (inc >= 37.5 && inc < 38.5) && (lc == 3);
me = mean(radar(ind_x,ind_y));
end
end

採用された回答

Michael Haderlein
Michael Haderlein 2014 年 8 月 6 日
編集済み: Michael Haderlein 2014 年 8 月 6 日
You have to use & instead of && (as Sara suggested) AND your last statement must be inside the find brackets.
[ind_x,ind_y] =find (inc >= 37.5 & inc < 38.5 & lc == 3);
  2 件のコメント
Hana
Hana 2014 年 8 月 6 日
Thanks Michael,it is solved now. Now the me=mean(ind_x,ind_y) gives error, it should return a single mean value of radar from the indices found from the condition.
Michael Haderlein
Michael Haderlein 2014 年 8 月 7 日
Yesterday, I obviously didn't check your code very well. Let's go through it:
In each loop iteration, you will get the same result from the find function as its parameters do not change.
Then, you overwrite your loop iterators by the result of the find function (not recommended).
Third, are inc and lc matrices or vectors? In case of vectors, one of the outputs of find will always be 1.
Finally, even if you change the line with the find, me will be overwritten every iteration. I suppose that's also not your goal.
However, to get this code running and doing what it's supposed to do, we need more information. What is inc and lc and me?

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

その他の回答 (1 件)

Sara
Sara 2014 年 8 月 5 日
In find you need to use & not &&
  1 件のコメント
Hana
Hana 2014 年 8 月 6 日
I tried it with & also and get the same error.

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by