Operands to the || and && operators must be convertible to logical scalar values.

1 回表示 (過去 30 日間)
Taha Oguz Özen
Taha Oguz Özen 2020 年 12 月 16 日
コメント済み: Taha Oguz Özen 2020 年 12 月 17 日
Hello eveyone. I try to do if 30<q_degree<150, Fc=500; otherwise Fc=0. However I have Operands to the || and && operators must be convertible to logical scalar values problem.
Also, It doesn't solve the Fc as a matrix for q matrix. How can I fix this. Please help me.
q= 0:pi/360:2*pi;
q_degree= rad2deg(q)
%DİKKAT ET Fc Yİ BİR MATRİX OLARAK TANIMLAMADI!!!!!!!!
if (q_degree>30) && (q_degree<150)
Fc=500;
else
Fc=0;
end

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 12 月 17 日
編集済み: Cris LaPierre 2020 年 12 月 17 日
Logical scalar means 1 logical value. You have a vector of logical values. An if statement must have a single logical result from the conditional expression. To check that all values met the criteria, us all().
If you instead meant to check each individual value separately, you'll need to incorporate a for loop (or logical indexing).
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 12 月 17 日
Fc = zeros(size(q_degree));
Fc(30 < q_degree & q_degree < 150) = 500;
Be careful about the boundaries, about what is to happen if the values are exactly 30 or exactly 500.
Taha Oguz Özen
Taha Oguz Özen 2020 年 12 月 17 日
Thank you for your answer. It works.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by