How can I get rid of vectors that are nearly identical in a list?

1 view (last 30 days)
I currently have a list of vectors say, {{0,0,10^-15},{0,0,0},{1,1,0},{1,1,10^-15}} where the first and second vectors are essentially the same and so are the third and fourth. I'm trying to write a function that will take in these vectors and output a list with only two vectors one from each of the two kinds of vectors, for example {{0,0,0},{1,1,0}}. I don't want to use the round function because it isn't robust enough for what I'm going to be using. So instead I am trying to implement the following code,
a=[[0 0 0];[0 0 10^-15];[1 0 0];[1 0 10^-15]];
marker=zeros(size(a,1),size(a,1));
for i=1:size(a,1)
for j=1:size(a,1)
if ((norm(a(i,:)-a(j,:))<eps*1000)&(norm(a(i,:)-a(j,:))>-eps*1000))
marker(i,j)=1;
end
end
So my idea is that I will loop over my list of vectors and it will find the difference of each vector with every other vector in the list and take the norm of the resulting vector and if that number is really small it will record it in a rectangular array called marker. My only problem now is using the marker array to weed out the "redundant vectors" and report something like [[0 0 10^-15];[1 0 0]].

Accepted Answer

Steven Lord
Steven Lord on 30 Jun 2015
If you're using release R2015a or later, take a look at UNIQUETOL.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!