function [ X,eta] = plotMSD( MSD,n,partsize,conversion,timestep,col,colr,T)
%Plots MSD versus lag time
fig=figure(1)

set(gca,'FontName','Arial','FontSize',12)
whitebg('w')
X=zeros(1,3);
t=1;
num=.1;%normally 0.1 for 10% of data
for i=n
   if t==1
        loglog([0.075:0.075:7.5],10.*[0.075:0.075:7.5],'--','LineWidth',5,'Color',[.5 .5 .5])
        ax = get(fig,'CurrentAxes');
        set(ax,'XScale','log','YScale','log')
    
        hold on
    end
    
    MSD(:,1)=MSD(:,1)./(conversion(i,1).^2);
    logMSD=log10(MSD((1:round(length(MSD(:,1))*num)),1)) %cuts off data to include only 'num' % (rule of thumb 10-15% has the most confidence for a single set...)
    logtau=log10(MSD((1:round(length(MSD(:,1))*num)),2))
    X(1,1:2)=polyfit(logtau,logMSD,1)
    X(1,3)=partsize(i);
    %X(i,4)=MSD(find(round(MSD(:,2)*10)/10==1),1);
    tau=([MSD(1,2):timestep(i):MSD(round(length(MSD(:,1))*num),2)]);
    
         
    loglog(MSD(1:round(length(MSD(:,1))*num),2),MSD(1:round(length(MSD(:,1))*num),1),col(i,:),'MarkerSize',10)%,'MarkerFaceColor',col(i,:),'MarkerSize',20)
    
    
    hold on
    loglog(tau,10^(X(1,2)).*tau.^X(1,1),colr(i),'Linewidth',2,'HandleVisibility','off')
    hold on
    clear logMSD logtau msd
    t=t+1;
     
end
xlabel('Lag Time \tau (s)')
ylabel('MSD (\mum^2)')
set(gca,'FontSize',18)
%Plots MSD versus lag time, but scaled in terms of bead size

% fig2=figure(2)
% set(gca,'FontName','Arial','FontSize',12)
% whitebg('w')
% Y=zeros(n,3);
% for i=n
%    if t==1
%         loglog([0.075:0.075:7.5],10.*[0.075:0.075:7.5],'--','LineWidth',5,'Color',[.5 .5 .5])
%         ax = get(fig,'CurrentAxes');
%         set(ax,'XScale','log','YScale','log')
%     
%         hold on
%     end
%     
%     MSD(:,1)=MSD(:,1)./(conversion(i,1).^2);
%     logMSD=log10(MSD((1:round(length(MSD(:,1))*num)),1)*partsize(n)/2)
%     logtau=log10(MSD((1:round(length(MSD(:,1))*num)),2))
%     Y(i,1:2)=polyfit(logtau,logMSD,1)
%     Y(i,3)=partsize(i);
%     %X(i,4)=MSD(find(round(MSD(:,2)*10)/10==1),1);
%     tau=([MSD(1,2):timestep(i):MSD(round(length(MSD(:,1))*num),2)]);
%     
%          
%     loglog(MSD(1:round(length(MSD(:,1))*num),2),MSD(1:round(length(MSD(:,1))*num),1)*partsize(n)/2,col(i,:),'MarkerSize',20)%,'MarkerFaceColor',col(i,:),'MarkerSize',20)
%     
%     
%     hold on
%     loglog(tau,10^(Y(i,2)).*tau.^Y(i,1),colr(i),'Linewidth',5,'HandleVisibility','off')
%     hold on
%     clear logMSD logtau msd
%     t=t+1;
%      
% end
% 
% xlabel('Lag Time \tau (s)')
% ylabel('MSD (\mum^2) * a (\mum)')

alpha=X(i,1); % unitless    
Diff=(10.^(X(i,2)))/4*(10^-12) %m^2/s  
eta=(1.38E-23)*T/6/pi/(partsize(i)./2.*10^-6)/ Diff(i,1); %Pa-s (mass/length/time)
end


