MATLAB: Getting an entire row containing the max value in column n in a matrix

matrixmaximum

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 !!

Best Answer

N=5
out=zeros(10,3);
for k=1:10
A=rand(N,3);
[~,idx]=max(A(:,2));
out(k,:)=A(idx,:);
end