MATLAB: How get the number in a row above

number above

Hello friends, i have a question.
For example, i got the Matrix:
r = [1 2;-2 -3]
r =
1 2
-2 -3
Then, i wanted to find the smallest number in the second row, so i did this:
ans =
But my question is, how can i get the number in the first row, that is above that smallest number (in this case, the number 2)? Is there any efficient way to do this in Matlab? I've tried doing it with the find fuction, but no succes so far.
Thanks in advance!

Best Answer

  • One approach:
    r = [1 2;-2 -3];
    [r2min,idx] = min(r(2,:));
    ElementAbove = r(1,idx)