function [outdata]=cleandata(data)

%Check if they are data to be eliminated 
figure(1)
scatter(data(:,1),data(:,2),4,data(:,3))

hold on 

disp('Focus in the desired area of the figure and then press Enter')
zoom on
pause

disp('Indicate if they are data to be eliminated, Yes(n=1) / No(n=0)')
n=input('n=');
rep=1;

j=1;
 while rep == 1
     xc=[]; yc=[];
     if j==2;
        data=outdata;
         figure(j)
     elseif j>=3
        data=outdata;
        figure(j)
       % scatter(data(:,1),data(:,2),4,data(:,3))
        disp('Focus in the desired area of the figure and then press Enter')
        zoom on
     end
     switch n
         case 1;
             disp('Introduce the corners of the polygon that includes the data to be eliminated');
             %[xc,yc] = ginput();
             hold on
             i=0;
             but = 1;
             
             disp('Select polygon to exclude in bathy')
             disp('Left mouse button picks points.')
             disp('Right mouse button picks last point.')
             while but == 1
                 i = i+1;
                 [xc(i),yc(i),but] = ginput(1);
                 plot(xc,yc,'r-o');
             end
             xc = [xc' ; xc(1)]; yc = [yc' ; yc(1)];
             in = inpolygon(data(:,1),data(:,2),xc,yc);
             plot(xc,yc,data(in,1),data(in,2),'k+')
             j=j+1;
         case 0
     end
     [outdata]=data(~in,:);
     figure(j)
     scatter(outdata(:,1),outdata(:,2),4,outdata(:,3))
     zoom on
     disp('Focus in the desired area of the figure and then press Enter')
     pause
     
     disp('Do you want to eliminate more data ?, Yes(rep=1) / No(rep=0)')
     rep=input('rep=');
 end
 
  