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

Asked by Bashir Yusuf Bichi on 7 Nov 2017
Latest activity Commented on by Fahim MUMAND about 20 hours ago
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

  4 Comments

Show 1 older comment
[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.
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?

Sign in to comment.