If statement with an greater than comparison

97 ビュー (過去 30 日間)
James
James 2014 年 10 月 6 日
コメント済み: José-Luis 2014 年 10 月 6 日
Hi,
I am trying to write an "if" statement between 2 values. I have a value "A" and a value "B". I want to set C to the value of A or B that is larger.
So like if A>B then C=A, otherwise C=B.
I am having trouble getting the proper code for this in matlab though.
Thanks

採用された回答

Guillaume
Guillaume 2014 年 10 月 6 日
It's pretty much what you've written:
if A > B
C = A;
else
C = B;
end
  1 件のコメント
José-Luis
José-Luis 2014 年 10 月 6 日
C = (A>B).*A + (~A>B).*B;
Works for arrays as well.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by