function [x,y,z,RepeatIndeces,repeats Q]=redundnt(x,y,z) % % [x,y,z,RepeatIndeces,repeats Q]=redundnt(x,y,z) % % [redundnt] averages all z's which have the same x and y coordinates, and % truncates the length of x and z by number of repeats. % {repeats} stores the coordinate(s) of the repeated stations, and % the number of occurences at each station % Q is the std of repeats/mean of repeats %*********************************************************************************** % % Jim Merriam % University of Saskatchewan % jim.merriam@usask.ca % (Jan 1997) % (last Sept 1998) % %*********************************************************************************** repeats=[]; % initialize x1=x; % y1=y; % working copies of input vectors z1=z; % n=0; % index for number of repeat locations for j=1:length(x) % cycle through input vector k=find(x(j)==x1 & y(j)==y1) ; % find indices of repeats if length(k)>1 % test for existence of repeats n=n+1; repeats(n,1)=x(j); repeats(n,2)=y(j); repeats(n,3)=z(j); repeats(n,4)=length(k); % number of repeats at each location z1(k) Q(j)=std(z1(k))/mean(z1(k)); z1(j)=mean(z1(k)); % first of repeats=average of repeats x1(k(2:length(k)))=NaN*k(2:length(k)); % NaN all repeats y1(k(2:length(k)))=NaN*k(2:length(k)); % NaN all repeats end end RepeatIndeces=find(isnan(x1)); % find Nan's in working x x1(RepeatIndeces)=[]; % y1(RepeatIndeces)=[]; % clear all NaN's (repeats) z1(RepeatIndeces)=[]; % x=x1; y=y1; % copy working back to original z=z1;