필터 지우기
필터 지우기

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.

답변 (1개)

the cyclist
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
belle
belle 2016년 12월 11일
The sort command won't compare the columns and will only sort the values in each column independently of other columns (I think).
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.
the cyclist
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 CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by