finding maximum in a row and subtracting.
2 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Walter Roberson
on 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)
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!