Borrar filtros
Borrar filtros

finding maximum in a row and subtracting.

1 visualización (últimos 30 días)
zozo
zozo el 5 de En. de 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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de En. de 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)

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by