필터 지우기
필터 지우기

finding maximum in a row and subtracting.

조회 수: 2 (최근 30일)
zozo
zozo 2012년 1월 5일
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