finding maximum in a row and subtracting.

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2012-1-5
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by