Finding multiple minimum number in a column and location

Hello, I have a matrix X =
100 14 10 4 10 6
101 2 8 8 12 18
102 8 4 8 18 14
103 2 12 8 8 18
104 5 15 5 5 15
105 8 16 6 4 12
106 7 11 3 9 13
107 16 12 6 8 4
108 12 10 2 10 8
109 6 6 4 14 14
For second column, 2. and 4. rows are 2 and they are the smallest number.. If there is more then one same smallest number how can I find all of them location?

답변 (2개)

madhan ravi
madhan ravi 2018년 10월 27일
편집: madhan ravi 2018년 10월 27일
a=[ 100 14 10 4 10 6
101 2 8 8 12 18
102 8 4 8 18 14
103 2 12 8 8 18
104 5 15 5 5 15
105 8 16 6 4 12
106 7 11 3 9 13
107 16 12 6 8 4
108 12 10 2 10 8
109 6 6 4 14 14]
id=(min(a))
[idy,idx]=find(ismember(a,id))
location = [idx idy] %idx represent row number and idk column number

댓글 수: 3

It doesnt work, I need to find minimum number of every column and location... however, second column has 2 minimum number so I should find 2 location for that one
madhan ravi
madhan ravi 2018년 10월 27일
편집: madhan ravi 2018년 10월 27일
see edited , each row in location represents position of minimum of each column
still doesn't work, test with
a = [1 10;
10 20]
It will return the position of lower-left 10, which is not wanted.

댓글을 달려면 로그인하십시오.

Bruno Luong
Bruno Luong 2018년 10월 27일
편집: Bruno Luong 2018년 10월 27일
X = [...
100 14 10 4 10 6
101 2 8 8 12 18
102 8 4 8 18 14
103 2 12 8 8 18
104 5 15 5 5 15
105 8 16 6 4 12
106 7 11 3 9 13
107 16 12 6 8 4
108 12 10 2 10 8
109 6 6 4 14 14]
[row,col] = find(X == min(X,[],1));
position = [row,col]
>>
1 1
2 2
4 2
3 3
9 4
6 5
8 6

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2018년 10월 27일

다시 열림:

2018년 11월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by