Find a Maximum in a Matrix

Hello all,
I am trying to find a maximum in a 484x1800 matrix. Particularly i´d need the index of the maximum of each row.
The result should be a 484x1 vector or 1x484 with the index of each maximum on each place of the vector.
I tried a few things with find and max and max(abs.... but it seems that the subscription in a matrix does not fit with these functions.
Please help,
Thanks,

 채택된 답변

Thomas
Thomas 2012년 7월 16일

0 개 추천

There probably is a more elegant solution but this should work
a=rand(40,10); %some random 40x10 data
for i=1:length(a)
[~,c(i),~]=find(a(i,:)==max(a(i,:)));
end
values=max(a,[],2);
% this is the largest value in each row and its position in the row
output=[c' values]

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 7월 16일

3 개 추천

X = rand(484,1800);
[maxval,idxmax] = max(X,[],2)
and for more info
doc max

댓글 수: 1

Thomas
Thomas 2012년 7월 16일
+1 I forgot that max gives the value and index.. :)

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2012년 7월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by