Effacer les filtres
Effacer les filtres

finding maximum in a row and subtracting.

2 vues (au cours des 30 derniers jours)
zozo
zozo le 5 Jan 2012
I have a matrix:
t=[2,3,8,6;44,56,6,77;74,23,45,67;12,34,45,23];
I want to find the maximum value from each row,subtract it from the rest of the elements in that row and store them row-wise in a matrix 'out',
that is:
out= [6,5,0,2;33,21,71,0;0,51,29,7;33,11,0,22]
Please help.

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Jan 2012
Your description would be coded as
out = t - repmat(max(t,[],2), 1, size(t,2));
but your example is the negative of that,
out = repmat(max(t,[],2), 1, size(t,2)) - t;
When you subtract the largest value in a row "from the rest of the elements in that row", the largest result you can get would be 0 (at the positions that match the maximum)
  1 commentaire
zozo
zozo le 5 Jan 2012
Thank you Sir.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices 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