I'm trying to make a search algorithm which finds the unique columns of a cell based on a tolerance level. The unique
function of MATLAB (R2012a), does not provide a tolerance input. Below is the code which I have so far; I have limited myself to checking uniqueness based on the first identity (j=1) for now, however, this needs to be updated later.
The output is: I obtain a store cell which contains all the vector expect the duplicates of [0;1;0]
. However other duplicate are maintained (e.g. [1;0;-0.4]
)
clear all; close all; clc;
%%
tolerance=1e-6;
U_vector{1} = [0 1 0 1 1 0 1 0 1 1;
1 0 1 0 0 1 0 1 0 0;
0 -0.4238 0 0.4238 -0.4238 0 0.4238 0 0.8161001 -0.8161];
for i = 1:1:size(U_vector,2)
k=1;
store{i}(:,k) = U_vector{i}(:,k);
for j=1;%:1:(size(U_vector{i},2))
for m=j:1:(size(U_vector{i},2))
if (abs(U_vector{i}(:,j)-U_vector{i}(:,m)) >= tolerance)
k=k+1;
store{i}(:,k) = U_vector{i}(:,m);
end
end
end
end