What does a = b > c specify in MATLAB syntax?
5 ビュー (過去 30 日間)
古いコメントを表示
My guess is that it is a shorthand for an if-else condition where a = 1 if b>c is true. Is this correct? If yes, can I replace a = b > c with a suitable if else condition?
0 件のコメント
採用された回答
Walter Roberson
2017 年 10 月 12 日
Yes, you can replace it with
if b > c
a = logical(1);
else
a = logical(0);
end
Another way of expressing this is:
if b > c
a = true;
else
a = false;
end
This is not the same as
if b > c
a = 1;
else
a = 0;
end
because in this later code, a = 1 or a = 0 assigns values of class double() to a, which behaves differently than when values of class logical() are assigned to a .
1 件のコメント
Walter Roberson
2022 年 11 月 15 日
Note that using if/else like this is only valid for the case that a and b are both scalars.
参考
カテゴリ
Help Center および File Exchange で Argument Definitions についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!