Finding the max of column 2 and column 3

2 vues (au cours des 30 derniers jours)
alpedhuez
alpedhuez le 24 Juil 2020
Commenté : alpedhuez le 24 Juil 2020
I have a matrix like
1 3 4
1 2 6
1 1 5
1 4 3
What I would like to do is to, for each row, take a max of column 2 and column 3. That is, the output will be like
1 3 4 4
1 2 6 6
1 1 5 5
1 4 3 4
I would like to know whether it is possible to do this calculation without writing a loop.

Réponse acceptée

madhan ravi
madhan ravi le 24 Juil 2020
[matrix, max(of second and third column of the matrix along rows)]
  2 commentaires
madhan ravi
madhan ravi le 24 Juil 2020
Did you take up the MATLAB On-ramp course? You seem to be asking the basic questions over and over again?
alpedhuez
alpedhuez le 24 Juil 2020
I know how to write a loop. I jjust wanted to understand whether there is a better way than loop. Having said that I will work on it.

Connectez-vous pour commenter.

Plus de réponses (1)

David Hill
David Hill le 24 Juil 2020
A(:,4)=max(A(:,2:3),[],2);
  1 commentaire
alpedhuez
alpedhuez le 24 Juil 2020
Let me work on it.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by