Biuld Min Index Array from Two dimensional Array

Hi Guys,
I got a question on Matlab. I am trying to build Array of min values from Two dimensional Array. Basically, the idea is to look for minimum value at each column & record the index.
If there are more then one minimum value then record it in different array, but the new array upto that point should be similar to previous one.
Its like finding minimum values link from mxn array.
Can you please help me to efficiently code this?
Thanks

답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 6월 30일

0 개 추천

[junk, index] = min(your_matrix); %will get you the first index
To get all minimum indices:
A = magic(4); %sample
A(7) = 2; %set duplicate for example
[r c] = find(bsxfun(@eq,min(A),A)); %all column mins
colmindex = accumarray(c,r,[],@(x){x})' %bin them into a row vector cell array with each index
Ruk Niz
Ruk Niz 2011년 6월 30일

0 개 추천

Hi Sean, Thanks for reply. This gives me the first Minimum at each column.
I am hoping to build multiple level of index. If say one column contains more than 1 minimum then I would like to create multiple single index array.
Say A =
0 0 1 2 3 4
2 3 1 3 4 1
1 1 2 0 3 7
>> [junk, index] = min(A)
junk =
0 0 1 0 3 1
index =
1 1 1 3 1 2
Gives only the first minimum index but if you look at the matrix. I am hoping to get the following
index1 = 1 1 1 3 1 2 index2 = 1 1 2 3 1 2 index3 = 1 1 1 3 3 2 index4 = 1 1 2 3 3 2
same for junk variable.
Rdgs Ruk

댓글 수: 1

See the update... and perhaps the FAQ on why to avoid using index1...4

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2011년 6월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by