How to select last location of min value which is avalable in more than one location of a 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?

 Akzeptierte Antwort

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

6 Kommentare

thank you, but when I tried B = [2 7 4; 8 4 2; 9 2 7] where I added one more value=2 in the location (3,2) and used the method [row,col]= find(A == min(min(A)),1, 'last') I got answer as (2,3) instead of last location (3,2). May I know why am I getting that result?
I typed the matrix name wrongly as "B". Actually it should be "A"
for matlab (2,3) comes after (3,2)
So how should I select the last location? I mean, I want to select the highest row location no matter what the column location is. Kindly help me
If you want it to give you the highest row as the last one, try
B = [2 7 4; 8 4 2; 9 2 7]
[row,col]= find(B == min(min(B)));
output_row=row(find(row==max(row)))
outuput_col=col(find(row==max(row)))
Thank you very much for providing solution to this issue.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by