## 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

### Bashir Yusuf Bichi (view profile)

on 7 Nov 2017
Latest activity Commented on by Fahim MUMAND

### Mischa Kim (view profile)

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

### Mischa Kim (view profile)

on 7 Nov 2017
Edited by Mischa Kim

### Mischa Kim (view profile)

on 7 Nov 2017

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

Show 1 older comment
Mischa Kim

### Mischa Kim (view profile)

on 7 Nov 2017
[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.
Bashir Yusuf Bichi

on 7 Nov 2017
thank you
Fahim MUMAND

### Fahim MUMAND (view profile)

10 minutes ago
suppose a matrix R = ones(4,4)
Every element is maximum and minimum, how to extract their indices?
How to extract the indices of max or min if there are more than 1 in col and in row?