Remove close value for matrix

조회 수: 3 (최근 30일)
Laura
Laura 2013년 7월 11일
I have a matrix A with has dimension n x3
I want to remove the data values that are so close to certain value or repeated.
Let say A = [ 1 1 1; 1 1 1.5; 1.1 1.2 1 , so on ]
definitely they are closed and I cant use "unique" command because they are not repeated for all 3 values.
How to remove those value in certain distance: let say if the distance is less than or equal to .5, then remove that row. We can average those value that would be awesome all close value and replace it in the new matrix.
Note: A has unknown row, so it has to be a loop.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 11일
편집: Azzi Abdelmalek 2013년 7월 11일
A = [ 1 1 1; 1 1 1.5; 1.1 1.2 1 ;2 3 4;2.1 2.9 4.5]
tol=0.5*ones(1,size(A,2));
v=(1:size(A,1));
idx=arrayfun(@(x) all(bsxfun(@le,abs(bsxfun(@minus,A,A(x,:))),tol),2),v,'un',0);
idx=cell2mat(idx);
for k=1:size(idx,1)
q=idx(:,k);
A(q,:)=repmat(mean(A(q,:)),sum(q),1);
end
out=unique(A,'rows')

추가 답변 (1개)

Matt J
Matt J 2013년 7월 11일
편집: Matt J 2013년 7월 11일
This one seems to be pretty popular
I'm sure you could browse the FEX for still more clustering algorithms.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by