Finding the second smallest value in each column of an array?
2 ビュー (過去 30 日間)
古いコメントを表示
This is probably very simple. I have an array of size, say 10 by 30. In each column, there is definitely an element with a value of 0, the rest of the nine: values > 0. Now, I want a row vector containing the second smallest values from each column of the original array.
Any idea? If I were to use min(array), I would get a row vector with all 0's. Maybe I have to use bubble sorting?
回答 (3 件)
Jan
2011 年 8 月 7 日
Sorting is a good idea:
X = rand(10, 10);
Xs = sort(X);
min2nd = Xs(2, :);
This is not very efficient, but most likely the fastest Matlab method.
0 件のコメント
Pierre
2011 年 8 月 7 日
You could simply take advantage of Bruno Luong's Min/Max selection implemented in MEX. AFAIK they implement Hoare's selection algorithm (which is a deviation of quicksort).
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!