MATLAB: How to select last location of min value which is avalable in more than one location of a matrix

minimum value locationselecting last location in the matrix

If I have a matrix, say A = [2 7 4; 8 4 2; 9 7 7], and if I want to find the min value ( which is 2 in this case) location, I can use [row,col]= find(A == min(min(A))) which gives two location. i.e., in this matrix we have "2" as the smallest value and it is available in two location. so we get [row,col] = (1,1) and (2,3). Now if I want to use the last location i.e., (2,3) instead of first location (1,1) for next operation. How to select last location? I tried using [row,col]= find(A == min(min(A)), 'last'), but it didn't work. Any suggestions?

Best Answer

[row,col]= find(A == min(min(A)),1, 'last')
row =
2
col =
3