MATLAB Answers

1

how to find min or max value in each row of a matrix and its index, if a matrix is 3x2 it will find the min in first row

R= [27 25 21; 35 38 37; 42 47 49]; 1st min value will be 21

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Mischa Kim
on 7 Nov 2017
Edited by Mischa Kim
on 7 Nov 2017
 Accepted Answer

Use
[val,loc] = min(R')
val =
21 35 42 % min value in each row
loc =
3 1 1 % column location of min value

  3 Comments

thank you for you help, but how can I access 1 row at a time?
[val,loc] = min(R(1,:)) % min value in 1st row
val =
21
loc =
3
Replace the "1" in the min command by a running index to step through each row, e.g., using a loop.

Sign in to comment.