function [smxy]=smoothline2(xy,rng,method)
%Smooth out a line

if nargin<3
    method='mean';
end

rng=round(rng/2); %(equal amount on both sides)
smxy=xy(1:rng,:);
for k=rng+1:length(xy)-rng
    if strcmp(method,'median')
        smxy(k,1:2)=median(xy(k-rng:k+rng,:));
    else
        smxy(k,1:2)=mean(xy(k-rng:k+rng,:));
    end
end
smxy=cat(1,smxy,xy(end-rng+1:end,:));