MATLAB: How to find the third largest number in a matrix? maxminsort Hey, Please help me find the third largest element in a matrix. I also want to find its position so I don't think sort() will work. I found this max(A(A<max(A(:)))) to work but it only show the second number not the third. Best, Best Answer First sort it in descending order[sortedMatrix, sortOrder] = sort(yourMatrix(:), 'descend');Then take the third element of each vector:thirdLargest = sortedMatrix(3)originalIndex = sortOrder(3) % A linear index.% Convert from linear subscript to row and column.[row, column] = ind2sub(size(yourMatrix), originalIndex)Why do you say that won't work? Related SolutionsMATLAB: Finding 2nd minimum value in an array A2 = sort(A(:));out = A2(2);other way:A2 = unique(A(:));out = A2(2);or:out = min(setdiff(A(:),min(A(:))));etc. MATLAB: Returning Position in Array or Matrices for max() [maxval, maxidx] = max(YourMatrix(:));[row, col] = ind2sub(size(YourMatrix), maxidx); Related QuestionHow to find second largest OR third largest Or any largest value among the columns of a matrixHow can i make a function which will return the largest and the second largest componentSort a matrix based on a maximum value in each rowLocation of 10 highest valuesRank matrix elements in descending order
Best Answer