filename = '50x100clminus10.txt';

rawdata = load(filename);
N = length(rawdata(:,1));

data =[];
for i = 1:N
    if((rawdata(i,1)>0)&&(rawdata(i,2)>0))
        data = [data; rawdata(i,:)];
    end
end

data = sortrows(data,1);
N = length(data(:,1));
plot(data(:,1),data(:,2),'.k');
xlabel('Depth (nm)','fontsize',12);
ylabel('Force (uN)','fontsize',12);
title('Spring constants of 50x100 cantilever','fontsize',12);

p = polyfit(data(:,1),data(:,2),1); % linear term is p(1)

yfit = p(1)*data(:,1)+p(2);
hold on;
plot(data(:,1),yfit,'r','linewidth',2);

p(1)