disp('LLCorrAnal1fig2.m') ;
A=load('D:\Research\NetworkData\ResponseSize\DataUNC2001\20010425_1300.rsps.txt') ;
flagnon0dur = A(:,3) > 0 ; % for only nonzero duration
n=size(flagnon0dur);
f_size = A(flagnon0dur,1); %size
duration = A(flagnon0dur,3); %duration
clear flagnon0dur;

log_size=log10(f_size);
log_dur=log10(duration);
log_rate=log_size-log_dur;

clear f_size duration ;

sthr1 = 3 ;
sthr2 = 4 ;
sthr3 = 5 ;
dthr1 = -3 ;
dthr2 = -2 ;
dthr3 = -1 ;
dthr4 = 0 ;
dthr5 = log10(5) ;

s1=A(:,1)>10^sthr1 & A(:,3)>0;
s2=A(:,1)>10^sthr2 & A(:,3)>0;
s3=A(:,1)>10^sthr3 & A(:,3)>0;

size_s1 = A(s1,1); %size
dur_s1 = A(s1,3); %duration

size_s2 = A(s2,1); %size
dur_s2 = A(s2,3); %duration
size_s3 = A(s3,1); %size
dur_s3 = A(s3,3); %duration
clear s1 s2 s3;

log_sizes1=log10(size_s1);
log_durs1=log10(dur_s1);
clear size_s1 dur_s1;
log_rates1=log_sizes1-log_durs1;
log_sizes2=log10(size_s2);
log_durs2=log10(dur_s2);
clear size_s2 dur_s2;
log_rates2=log_sizes2-log_durs2;
log_sizes3=log10(size_s3);
log_durs3=log10(dur_s3);
clear size_s3 dur_s3;
log_rates3=log_sizes3-log_durs3;

d1=A(:,3)>10^dthr1;
d2=A(:,3)>10^dthr2;
d3=A(:,3)>10^dthr3;
d4=A(:,3)>10^dthr4;
d5=A(:,3)>10^dthr5;

size_d1 = A(d1,1); %size
dur_d1 = A(d1,3); %duration
size_d2 = A(d2,1); %size
dur_d2 = A(d2,3); %duration
size_d3 = A(d3,1); %size
dur_d3 = A(d3,3); %duration
size_d4 = A(d4,1); %size
dur_d4 = A(d4,3); %duration
size_d5 = A(d5,1); %size
dur_d5 = A(d5,3); %duration


clear d1 d2 d3 d4 d5 ;

log_sized1=log10(size_d1);
log_durd1=log10(dur_d1);
clear size_d1 dur_d1;
log_rated1=log_sized1-log_durd1;
log_sized2=log10(size_d2);
log_durd2=log10(dur_d2);
clear size_d2 dur_d2;
log_rated2=log_sized2-log_durd2;
log_sized3=log10(size_d3);
log_durd3=log10(dur_d3);
clear size_d3 dur_d3;
log_rated3=log_sized3-log_durd3;
log_sized4=log10(size_d4);
log_durd4=log10(dur_d4);
clear size_d4 dur_d4;
log_rated4=log_sized4-log_durd4;
log_sized5=log10(size_d5);
log_durd5=log10(dur_d5);
clear size_d5 dur_d5;
log_rated5=log_sized5-log_durd5;

sd11=A(:,1)>10^sthr1 & A(:,3)>10^dthr1;
size_sd11 = A(sd11,1);
dur_sd11 = A(sd11,3); 
clear sd11;
log_sizesd11=log10(size_sd11);
log_dursd11=log10(dur_sd11);
clear size_sd11 dur_sd11;
log_ratesd11=log_sizesd11-log_dursd11;

sd21=A(:,1)>10^sthr2 & A(:,3)>10^dthr1;
size_sd21 = A(sd21,1);
dur_sd21 = A(sd21,3);
clear sd21;
log_sizesd21=log10(size_sd21);
log_dursd21=log10(dur_sd21);
clear size_sd21 dur_sd21;
log_ratesd21=log_sizesd21-log_dursd21;

sd31=A(:,1)>10^sthr3 & A(:,3)>10^dthr1;
size_sd31 = A(sd31,1);
dur_sd31 = A(sd31,3);
clear sd31;
log_sizesd31=log10(size_sd31);
log_dursd31=log10(dur_sd31);
clear size_sd31 dur_sd31;
log_ratesd31=log_sizesd31-log_dursd31;

sd12=A(:,1)>10^sthr1 & A(:,3)>10^dthr2;
size_sd12 = A(sd12,1);
dur_sd12 = A(sd12,3);
clear sd12;
log_sizesd12=log10(size_sd12);
log_dursd12=log10(dur_sd12);
clear size_sd12 dur_sd12;
log_ratesd12=log_sizesd12-log_dursd12;

sd22=A(:,1)>10^sthr2 & A(:,3)>10^dthr2;
size_sd22 = A(sd22,1);
dur_sd22 = A(sd22,3);
clear sd22;
log_sizesd22=log10(size_sd22);
log_dursd22=log10(dur_sd22);
clear size_sd22 dur_sd22;
log_ratesd22=log_sizesd22-log_dursd22;

sd32=A(:,1)>10^sthr3 & A(:,3)>10^dthr2;
size_sd32 = A(sd32,1);
dur_sd32 = A(sd32,3);
clear sd32;
log_sizesd32=log10(size_sd32);
log_dursd32=log10(dur_sd32);
clear size_sd32 dur_sd32;
log_ratesd32=log_sizesd32-log_dursd32;

sd13=A(:,1)>10^sthr1 & A(:,3)>10^dthr3;
size_sd13 = A(sd13,1);
dur_sd13 = A(sd13,3);
clear sd13;
log_sizesd13=log10(size_sd13);
log_dursd13=log10(dur_sd13);
clear size_sd13 dur_sd13;
log_ratesd13=log_sizesd13-log_dursd13;

sd23=A(:,1)>10^sthr2 & A(:,3)>10^dthr3;
size_sd23 = A(sd23,1);
dur_sd23 = A(sd23,3);
clear sd23;
log_sizesd23=log10(size_sd23);
log_dursd23=log10(dur_sd23);
clear size_sd23 dur_sd23;
log_ratesd23=log_sizesd23-log_dursd23;

sd33=A(:,1)>10^sthr3 & A(:,3)>10^dthr3;
size_sd33 = A(sd33,1);
dur_sd33 = A(sd33,3);
clear sd33;
log_sizesd33=log10(size_sd33);
log_dursd33=log10(dur_sd33);
clear size_sd33 dur_sd33;
log_ratesd33=log_sizesd33-log_dursd33;

sd14=A(:,1)>10^sthr1 & A(:,3)>10^dthr4;
size_sd14 = A(sd14,1);
dur_sd14 = A(sd14,3);
clear sd14;
log_sizesd14=log10(size_sd14);
log_dursd14=log10(dur_sd14);
clear size_sd14 dur_sd14;
log_ratesd14=log_sizesd14-log_dursd14;

sd24=A(:,1)>10^sthr2 & A(:,3)>10^dthr4;
size_sd24 = A(sd24,1);
dur_sd24 = A(sd24,3);
clear sd24;
log_sizesd24=log10(size_sd24);
log_dursd24=log10(dur_sd24);
clear size_sd24 dur_sd24;
log_ratesd24=log_sizesd24-log_dursd24;

sd34=A(:,1)>10^sthr3 & A(:,3)>10^dthr4;
size_sd34 = A(sd34,1);
dur_sd34 = A(sd34,3);
clear sd34;
log_sizesd34=log10(size_sd34);
log_dursd34=log10(dur_sd34);
clear size_sd34 dur_sd34;
log_ratesd34=log_sizesd34-log_dursd34;

sd15=A(:,1)>10^sthr1 & A(:,3)>10^dthr5;
size_sd15 = A(sd15,1);
dur_sd15 = A(sd15,3);
clear sd15;
log_sizesd15=log10(size_sd15);
log_dursd15=log10(dur_sd15);
clear size_sd15 dur_sd15;
log_ratesd15=log_sizesd15-log_dursd15;

sd25=A(:,1)>10^sthr2 & A(:,3)>10^dthr5;
size_sd25 = A(sd25,1);
dur_sd25 = A(sd25,3);
clear sd25;
log_sizesd25=log10(size_sd25);
log_dursd25=log10(dur_sd25);
clear size_sd25 dur_sd25;
log_ratesd25=log_sizesd25-log_dursd25;

sd35=A(:,1)>10^sthr3 & A(:,3)>10^dthr5;
size_sd35 = A(sd35,1);
dur_sd35 = A(sd35,3);
clear sd35;
log_sizesd35=log10(size_sd35);
log_dursd35=log10(dur_sd35);
clear size_sd35 dur_sd35;
log_ratesd35=log_sizesd35-log_dursd35;

clear A;

        
titlefontsize = 15 ;
textfontsize = 6 ;
labelfontsize = 12 ;

left = 0 ;
right = 9 ;
top = 11 ;
bottom = -2 ;

nplot=length(log_size);  
plot(log_size,log_rate, 'c.') ;
axis([left,right,bottom,top]) ;
%title(['Thursday afternoon log - log Scatterplot, for all non-0 Durations, n = ' num2str(nplot)],'FontSize',titlefonsize) ;
xlabel('log_{10}(size)','FontSize',labelfontsize) ;
ylabel('log_{10}(rate)','FontSize',labelfontsize) ;

hold on ;
plot([sthr1,sthr1],[bottom,top],'r--');
plot([sthr2,sthr2],[bottom,top],'r--'); 
plot([sthr3,sthr3],[bottom,top],'r--'); 
plot([left,right], [left-dthr1,right-dthr1],'r--');
plot([left,right], [left-dthr2,right-dthr2],'r--');
plot([left,right], [left-dthr3,right-dthr3],'r--');
plot([left,right], [left-dthr4,right-dthr4],'r--');
plot([left,right], [left-dthr5,right-dthr5],'r--');

c=corrcoef(log_size,log_rate);
text(1.5,9.6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(1.5,9.2,' (100%)','Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizes1,log_rates1);
text(3,9.6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,9.2,['(' num2str(round(length(log_sizes1)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizes2,log_rates2);
text(4,9.6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,9.2,[' (' num2str(round(length(log_sizes2)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizes3,log_rates3);
text(5,9.6,[num2str(c(2,1)) ' (' num2str(round(length(log_sizes3)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');

c=corrcoef(log_sized1,log_rated1);
text(1.5,4.5,[num2str(c(2,1)) ' (' num2str(round(length(log_sized1)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sized2,log_rated2);
text(1.5,3.5,[num2str(c(2,1)) ' (' num2str(round(length(log_sized2)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sized3,log_rated3);
text(1.5,2.5,[num2str(c(2,1)) ' (' num2str(round(length(log_sized3)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sized4,log_rated4);
text(1.5,1.6,[num2str(c(2,1)) ' (' num2str(round(length(log_sized4)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sized5,log_rated5);
text(1.5,0.2,[num2str(c(2,1)) ' (' num2str(round(length(log_sized5)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd11,log_ratesd11);
text(3,6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,5.6,[' (' num2str(round(length(log_sizesd11)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd21,log_ratesd21);
text(4,7,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,6.6,[' (' num2str(round(length(log_sizesd21)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd31,log_ratesd31);
text(5,8,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd31)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd12,log_ratesd12);
text(3,5,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,4.6,[' (' num2str(round(length(log_sizesd12)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd22,log_ratesd22);
text(4,6,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,5.6,[' (' num2str(round(length(log_sizesd22)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd32,log_ratesd32);
text(5,7,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd32)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd13,log_ratesd13);
text(3,4,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,3.6,[' (' num2str(round(length(log_sizesd13)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd23,log_ratesd23);
text(4,5,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,4.6,[' (' num2str(round(length(log_sizesd23)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd33,log_ratesd33);
text(5,6,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd33)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd14,log_ratesd14);
text(3,3,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,2.6,[' (' num2str(round(length(log_sizesd14)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd24,log_ratesd24);
text(4,4,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,3.6,[' (' num2str(round(length(log_sizesd24)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd34,log_ratesd34);
text(5,5,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd34)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd15,log_ratesd15);
text(3,2,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(3,1.6,[' (' num2str(round(length(log_sizesd15)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd25,log_ratesd25);
text(4,2,[num2str(c(2,1))],'Fontsize',textfontsize, 'color', 'k');
text(4,1.6,[' (' num2str(round(length(log_sizesd25)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
c=corrcoef(log_sizesd35,log_ratesd35);
text(5,2,[num2str(c(2,1)) ' (' num2str(round(length(log_sizesd35)*1000/nplot)/10) '%)'],'Fontsize',textfontsize, 'color', 'k');
hold off ;

set(gca,'Box','on') ;

pstr = ['LLCorrAnal1fig2'] ;
orient portrait ;
  set(gcf,'PaperSize',[5.0, 5.0]) ; 
  set(gcf,'PaperPosition',[0.25, 0.25, 4.5, 4.5]) ;
print('-dpsc2',[pstr '.ps']) ;