필터 지우기
필터 지우기

Delete duplicate data in matrix, based on a column

조회 수: 9 (최근 30일)
Kasper Buchardt
Kasper Buchardt 2020년 11월 10일
댓글: Ameer Hamza 2020년 11월 11일
I have multiple test data which is arranged in a matrix like 'A'. Column 1 = x-axis, column 2 = y-axis.
In order to interpolate I need to delete duplicate x-values. There is some insignificant variations in the corresponding y-values, hence it doesn't matter if it's the first or last that is kept.
Below is an example of the method i've tried. It deletes the rows where both columns are identical, but leaves the ones with different y-values
A = randi(5,10,2)
A = 10×2
4 3
3 1
5 2
4 1
5 2
3 3
2 3
1 3
4 5
4 3
B = unique(A,"rows","sorted")
B = 8×2
1 3
2 3
3 1
3 3
4 1
4 3
4 5
5 2
Is there a way to get matlab to use the first column for comparrison only, and delete the entire row?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 10일
편집: Ameer Hamza 2020년 11월 10일
If the difference in 2nd column values for the same first column value is insignificant, then you can try the following code
A = randi(5,10,2);
[~, idx] = unique(A(:,1));
A_unique = A(idx, :);
  댓글 수: 2
Kasper Buchardt
Kasper Buchardt 2020년 11월 11일
That did the trick. Thank you very much.
Ameer Hamza
Ameer Hamza 2020년 11월 11일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by