Ordering values in columns of an array according to the closest value in the previous column
2 ビュー (過去 30 日間)
古いコメントを表示
I have an array with complex numbers. Each column of the array corresponds to a new parameter. I would like to order the values of each column so that they are on the same row as the values on the previous column that are closest to them. At the moment, the code produces the two values between adjacent columns which are the closest rather than pairing up the values between adjacent columns that are the closest. Ultimately, I would like a new array with the values in their new order. Many thanks.
for j = 1:1:n-1;
difference = abs(eigenvaluearray(:,j)- eigenvaluearray(:,j+1));
[min,index] = min(difference)
orderedeigenvalues(index) = eigenvaluearray(j)
end
The type of ordering I'm looking for is (example with real numbers):
The values need to be ordered so that values in each column are paired up with the value in the previous column which is closest to it. E.g:
1 2
3 5
4 0
After reordering, this would give:
1 0
3 2
4 5
Because the differences between the values in the rows are the minimum.
0 件のコメント
回答 (1 件)
the cyclist
2016 年 12 月 11 日
I don't fully understand what you are trying to do, but I wonder if the sort command would be more useful than the min command.
2 件のコメント
the cyclist
2016 年 12 月 11 日
Right. So I was thinking something along the lines of
difference = abs(eigenvaluearray(:,j)- eigenvaluearray(:,j+1));
[min,index] = sort(difference)
using sort in place of min in your code.
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!