# Getting the entry value (i,j) for the minimum value of reach row of a matrix

4 views (last 30 days)
Wietze Zijpp on 9 Apr 2022
Commented: Voss on 9 Apr 2022
Suppose I have a matrix
A = 3×3
11 13 15
12 14 16
32 18 21
How do I get the output (1,1) (2,1) and (1,3) which indicate the position of the minimum value of each row.

Voss on 9 Apr 2022
A=[11 13 15
12 14 16
32 18 21];
[minrow,idx] = min(A,[],2) % min value of each row, with column index
minrow = 3×1
11 12 18
idx = 3×1
1 1 2
result = [(1:size(A,1)).' idx] % 18 is at (3,2) not (1,3)
result = 3×2
1 1 2 1 3 2
##### 2 CommentsShowHide 1 older comment
Voss on 9 Apr 2022
You're welcome!

Arif Hoq on 9 Apr 2022
may be you are looking for this:
A=[11 13 15
12 14 16
32 18 21];
mincol=min(A) % min value of each column
mincol = 1×3
11 13 15
minrow= min(A,[],2) % min value of each row
minrow = 3×1
11 12 18
Wietze Zijpp on 9 Apr 2022
This is what I was looking for, thank you.

### Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by