Effacer les filtres
Effacer les filtres

If statement with an greater than comparison

103 vues (au cours des 30 derniers jours)
James
James le 6 Oct 2014
Commenté : José-Luis le 6 Oct 2014
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

Réponse acceptée

Guillaume
Guillaume le 6 Oct 2014
It's pretty much what you've written:
if A > B
C = A;
else
C = B;
end
  1 commentaire
José-Luis
José-Luis le 6 Oct 2014
C = (A>B).*A + (~A>B).*B;
Works for arrays as well.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by