getting an entire row containing the max value in column n in a matrix
3 views (last 30 days)
Show older comments
Matthieu
on 5 Feb 2014
Commented: Azzi Abdelmalek
on 5 Feb 2014
Hello everyone,
here is my problem :
I have lots of files containing a matrix of the form N x 3 elements ; and I would like to extract the entire row containing the maximum value of the second column so I can write them in a new matrix.
I tried the MAX function but it gives me the maximum value of each row...
Any help ? Thank you !!
1 Comment
Azzi Abdelmalek
on 5 Feb 2014
Matthieu commented
Thank you very much for the fast answer !
I already had written the rest of the code so everythink is working now.
Thanks again !
Accepted Answer
Azzi Abdelmalek
on 5 Feb 2014
N=5
out=zeros(10,3);
for k=1:10
A=rand(N,3);
[~,idx]=max(A(:,2));
out(k,:)=A(idx,:);
end
0 Comments
More Answers (1)
Image Analyst
on 5 Feb 2014
Azzi gave you code for extracting the row that has the max in the array A. To get the arrays "A" from all your various files, see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
0 Comments
See Also
Categories
Find more on Shifting and Sorting 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!