Tuesday, March 16, 2010

Check if the data is already in there

I wanted to test if my new coming data was already contained in the set.
This is very easy!



test = rand(1,23);
A = test(5);
B = test-A;
BB = B(B==0);
if length(BB)>0
    disp('has it!!')
else
%%%  
end
%%%%%%%%%
% another attempt
clc
test = ceil(10*rand(1,10));
doit = 1;
jj =1
while doit
    A = ceil(10*rand);
    B = test-A;
    BB = B(B==0);
    if length(BB)>0
       
%         A = ceil(10*rand);
%         B = test-A;
%         BB = B(B==0);
        jj=jj+1;
        disp('test done!!')
       
    else
        doit = 0;
        %%%
    end
end




No comments: