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
2011 年 6 月 30 日
[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
2011 年 6 月 30 日
1 件のコメント
Sean de Wolski
2011 年 6 月 30 日
See the update... and perhaps the FAQ on why to avoid using index1...4
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!