채택된 답변

Walter Roberson
Walter Roberson 2015년 8월 22일

0 개 추천

[maxvals, maxidx] = max(YourMatrix, [], 2);
Now maxidx will be a vector of column numbers, one per row.

댓글 수: 4

abduall hassn
abduall hassn 2015년 8월 22일
Thanx brother but my problem i have index 364 from very index i want to select max value between five rows
Example
Index 1 the max value in colum 4
Index 2 the max value in colum 4
Index 3 the max value in colum 4
Index 4 the max value in colum 4
Index 5 the max value in colum 5
Index 6 the max value in colum 5
like this
You have 364 values. You cannot break that up into groups of 5 without having a group of 4 left over.
If you had 365 values or some other multiple of 5, then
max( reshape(maxidx, 5, []) )
abduall hassn
abduall hassn 2015년 8월 23일
편집: Walter Roberson 2015년 8월 23일
Thanx alot brother
But i want to ask. Why u give 2?
And think u again
[maxvals, maxidx] = max(YourMatrix, [], 2);
The 2 refers to dimension #2, the columns . The above functions equivalently to
for K = 1 : size(YourMatrix,1)
[maxvals(K,1), maxidx(K,1)] = max(YourMatrix(K,:),[]);
end
If you left out the 2, then the default would be to work along the first non-singular dimension, like
for K = 1 : size(YourMatrix,2)
[maxvals(1,K), maxidx(1,K)] = max(YourMatrix(:,K),[]);
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Error Handling에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2015년 8월 22일

편집:

2016년 11월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by