-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis_onset_buildup_avg.m
1894 lines (1667 loc) · 77.5 KB
/
analysis_onset_buildup_avg.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%function analysis_onset_buildup_avg
%function analysis_onset_buildup_avg
% Analysis of onset of build-up and burst activity of average spiking activity recorded with a
% laminar probe (LMA)
%
%
% Corentin Massot
% Cognition and Sensorimotor Integration Lab, Neeraj J. Gandhi
% University of Pittsburgh
% created 11/29/2016 last modified 01/23/2018
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%set paths
[root_path data_path save_path]=set_paths;
save_path=[root_path 'Results\Results_SC_onsetbuildup\'];
%screen size
scrsz = get(groot,'ScreenSize');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%parameters
%print figures and save data
savedata=0;
savefigs=0;
figtype='png';%'epsc2';
%alignement
%alignlist={'no' 'targ' 'go' 'sacc'};
alignlist={'sacc'};
%windows of analysis (do not change)
%for first results
%wind_sacc=[-400 250];%[-400 100]
%for detrend_500_300
wind_sacc=[-600 100];
%windows baseline
%wt=100;
%wind_targ_pburst_bsl=[-50-wt -50 ];
%wind_bsl_sacc=[-200 -100];%[-200 150];
%vshift
vshift_spk=100;
vshift_lfp=30;%29;
%start .pptx file
savepptx=0;
if savepptx
isOpen = exportToPPTX();
if ~isempty(isOpen),
% If PowerPoint already started, then close first and then open a new one
exportToPPTX('close');
end
exportToPPTX('new','Dimensions',[12 6], ...
'Title','SC onset buildup', ...
'Author','Corentin', ...
'Subject','Automatically generated PPTX file from output of analysis_onset_buildup_avg.m', ...
'Comments',' ');
%tmp filename
file=[save_path 'onset_buildup_tmp' '.' figtype];
%pptx filename
datenow=datestr(now);
datenow=[datenow(1:11) '-' datenow(13:14) 'h' datenow(16:17) 'm' datenow(19:20) 's']
filepptx=[save_path 'SC_onsetbuildup-' datenow]
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%get data
datalist=load_data_gandhilab(data_path);
%colorlist
colorlist=get_colorlist;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%analyzing data
dlist=get_dlist
allpeak={};allelb1={};allelb2={};allinflect1={};allinflect2={};allinflect3={};allaccum={};allburst={};
classif=struct;allscat={};
data=[];
info=[];
dd=0;
for d=dlist(1:end)
%counter
dd=dd+1;
%get data and info
info.datafile=datalist{d};
load ([data_path info.datafile]);
display(info.datafile)
%getting channel mapping and discard selected bad channels
[info.chmap info.nchannels info.depths]=get_chmap(data(1).info.electrode{2},[]);
%getting trial type
info.trialtype=data(1).sequence(1);
%getting list of targets
targslist=data(1).offline.targslist;
%targets index
targs_ind=get_targsindex(targslist,info);
%target tuning (after compute_tuning)
info.targ_tuning=data(1).offline.targ_tuning;
info.targ=info.targ_tuning;
%align 'sacc'
info.align=alignlist{1};
%aligntime
info.aligntime=abs(min(wind_sacc));
%sacc bursts significance
thresh_ratios=0.15;%0.15
thresh_surprises=4;
ratios_sacc=data(1).offline.sacc_pburst_ratio(info.targ_tuning,:)>thresh_ratios;
surprises_sacc=data(1).offline.sacc_pburst_msurprises(info.targ_tuning,:)>thresh_surprises;
bsignif_sacc=data(1).offline.sacc_bsignif;
bthresh_sacc=data(1).offline.sacc_bthresh_trials';
%burst_bsignif=(ratios_sacc & surprises_sacc & bsignif_sacc & bthresh_sacc);
burst_bsignif=(bsignif_sacc & bthresh_sacc);
burst_bsignif=double(burst_bsignif);
burst_bsignif(find(burst_bsignif==0))=nan;
%ntrials
info.ntrials=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %load results onsetbuildup for average trials
% nboot=1;
% nameload=[save_path 'results_onsetbuildup_' info.datafile(1:end-4) '_nboot' num2str(nboot)];
% load(nameload)
% %'trials_boot','peak_boot','elb1_boot','elb2_boot','inflect1_boot','inflect2_boot','inflect3_boot','resnorm1_boot','resnorm2_boot','resnorm3_boot');
%
% trials_avg=squeeze(trials_boot(1,:,:));
% peak_avg=squeeze(peak_boot(1,:,:));
% elb1_avg=squeeze(elb1_boot(1,:,:));
% elb2_avg=squeeze(elb2_boot(1,:,:));
% inflect1_avg=squeeze(inflect1_boot(1,:,1:2));
% inflect2_avg=squeeze(inflect2_boot(1,:,1:2));
% inflect3_avg=squeeze(inflect3_boot(1,:,1:2));
% %resnorm1_avg=resnorm1_boot{1};
% %resnorm2_avg=resnorm2_boot{1};
% %resnorm3_avg=resnorm3_boot{1};
%
%%
%%%%%%%%%%%%%%%%%%
% %plot avg and ste
% figtrials=figure('Position',[scrsz(3)/6 150 scrsz(3)/1.5 scrsz(4)-300]);
% hdlfig=subplot(1,1,1);hold on;
% [range_spk vshift_spk]=plot_trials(trials_avg,[],[],[],[],[],info,hdlfig,[],[],[]);
% %plot_trials(trials_avg+trials_var,[],[],[],[],[],info,hdlfig,[],'-',1);
% %plot_trials(trials_avg-trials_var,[],[],[],[],[],info,hdlfig,[],'-',1);
%
% %plot peak
% plot_events_ch(peak_avg.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','--',1,'k');
%
% %plot elb_1
% plot_events_ch(elb1_avg.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','--',1,'');
%
% %plot elb_2
% plot_events_ch(elb2_avg.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','-',1,'');
%
% %plot inflect 1
% plot_events_ch(inflect1_avg.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','-',2,'');
%
% %plot inflect 2
% plot_events_ch(inflect2_avg.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','--',2,'');
%
% %plot inflect 3
% plot_events_ch(inflect3_avg.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','-',2,'k');
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%load results onsetbuildup for bootstrapped trials
nboot=100;%551;%100;%20;
%suffixe='_newd';%'_newdfix';%fix point for 2pwlr %'_new';%'_inflect2_150';%''
suffixe='_detrend_500_300';%'_detrend_500_300_2';%change detrending and elb1 windows
nameload=[save_path 'results_onsetbuildup_' info.datafile(1:end-4) '_nboot' num2str(nboot) suffixe]
load(nameload)
%'trials_boot','peak_boot','elb1_boot','elb2_boot',...
%'inflect1_boot','inflect2_boot','inflect3_boot',...
%'resnorm1_boot','resnorm2_boot','resnorm3_boot',...
%'fitparams1_boot','fitparams2_boot','fitparams3_boot',...
%'resnormfit1_boot','resnormfit2_boot','resnormfit3_boot');
%%
%%%%%%%%%%%%%
%plot all bootstrapped trials
% %plot all trials boot
% figtrialsbootall=figure
% hdlfig=subplot(1,1,1);hold on;
% for b=1:nboot
% [range_spk vshift_spk]=plot_trials(squeeze(trials_boot(b,:,:)),[],[],[],[],[],info,hdlfig,[],[],[]);
% end
%%
%%%%%%%%%%%%%
%plot trials avg and ste
trials_boot_avg=squeeze(mean(trials_boot,1));
trials_boot_var=squeeze(std(trials_boot,1)/size(trials_boot,1));
figtrialsboot=figure;
hdlfig=subplot(1,1,1);hold on;
[range_spk vshift_spk]=plot_trials(trials_boot_avg,[],[],[],[],[],info,hdlfig,[],[],[]);
plot_trials(trials_boot_avg+trials_boot_var,[],[],[],[],[],info,hdlfig,[],'-',1);
plot_trials(trials_boot_avg-trials_boot_var,[],[],[],[],[],info,hdlfig,[],'-',1);
figtrialsboot2=figure;
hdlfig=subplot(1,1,1);hold on;
[range_spk vshift_spk]=plot_trials(trials_boot_avg,[],[],[],[],[],info,hdlfig,[],[],[]);
plot_trials(trials_boot_avg+trials_boot_var,[],[],[],[],[],info,hdlfig,[],'-',1);
plot_trials(trials_boot_avg-trials_boot_var,[],[],[],[],[],info,hdlfig,[],'-',1);
figtrialsboot3=figure;
hdlfig=subplot(1,1,1);hold on;
[range_spk vshift_spk]=plot_trials(trials_boot_avg,[],[],[],[],[],info,hdlfig,[],[],[]);
plot_trials(trials_boot_avg+trials_boot_var,[],[],[],[],[],info,hdlfig,[],'-',1);
plot_trials(trials_boot_avg-trials_boot_var,[],[],[],[],[],info,hdlfig,[],'-',1);
% %%%%%%%%%%%%%
% %plot all bootstrapped onsets
% for b=1:nboot
% %plot peak
% figure(figtrialsboot)
% onset_plot=[];onset_plot(:,1)=squeeze(peak_boot(b,:,1));onset_plot(:,2)=squeeze(peak_boot(b,:,2));
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','--',1,'k');
% %plot elb_1
% onset_plot=[];onset_plot(:,1)=squeeze(elb1_boot(b,:,1));onset_plot(:,2)=squeeze(elb1_boot(b,:,2));
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','--',1,'');
% %plot elb_2
% onset_plot=[];onset_plot(:,1)=squeeze(elb2_boot(b,:,1));onset_plot(:,2)=squeeze(elb2_boot(b,:,2));
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','-',1,'');
%
% %plot inflect 1
% figure(figtrialsboot2)
% onset_plot=[];onset_plot(:,1)=squeeze(inflect1_boot(b,:,1));onset_plot(:,2)=squeeze(inflect1_boot(b,:,2));
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','-',2,'');
% %plot inflect 2
% onset_plot=[];onset_plot(:,1)=squeeze(inflect2_boot(b,:,1));onset_plot(:,2)=squeeze(inflect2_boot(b,:,2));
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','--',2,'');
% %plot inflect 3
% onset_plot=[];onset_plot(:,1)=squeeze(inflect3_boot(b,:,1));onset_plot(:,2)=squeeze(inflect3_boot(b,:,2));
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n','-',3,'');
%
% end
%%
%%%%%%%%%%%%%
%compute CI
ci_level=0.95;%0.8;%95%
p_level=0.01;
peak_ci=[];elb1_ci=[];elb2_ci=[];inflect1_ci=[];inflect2_ci=[];inflect3_ci=[];
fitslopes1_boot=[];fitslopes1_1_ci=[];fitslopes1_2_ci=[];fitslopes1_diff_ci=[];tsignif_fitslopes1=[];
%fitslopes2_boot=[];fitslopes2_1_ci=[];fitslopes2_2_ci=[];
fitslopes3_boot=[];fitslopes3_1_ci=[];fitslopes3_2_ci=[];fitslopes3_diff_ci=[];tsignif_fitslopes3=[];
tsignif_elb1_inflect1=[];%tsignif_elb1_inflect3=[];
elb2_boot=nan(size(elb1_boot));
inflect2_boot=nan(size(elb1_boot));
for ch=1:info.nchannels
peak_ci(ch,1:3)=get_ci2(peak_boot(:,ch,1),ci_level);
elb1_ci(ch,1:3)=get_ci2(elb1_boot(:,ch,1),ci_level);
%elb1 ci normalization search window of elb1 is 250ms (see compute_onset_buildup_avg)
%elb1_ci(ch,4:5)=(elb1_ci(ch,2:3)-elb1_ci(ch,1))./250+elb1_ci(ch,1);
%elb1 ci normalization search window of elb1 is 300ms (see compute_onset_buildup_avg)
elb1_ci(ch,4:5)=(elb1_ci(ch,2:3)-elb1_ci(ch,1))./300+elb1_ci(ch,1);
elb2_ci(ch,1:3)=get_ci2(elb2_boot(:,ch,1),ci_level);
inflect1_ci(ch,1:3)=get_ci2(inflect1_boot(:,ch,1),ci_level);
%inflect1 ci normalization
inflect1_ci(ch,4:5)=(inflect1_ci(ch,2:3)-inflect1_ci(ch,1))./mean(abs(elb1_boot(:,ch,1)-peak_boot(:,ch,1)))+inflect1_ci(ch,1);
inflect2_ci(ch,1:3)=get_ci2(inflect2_boot(:,ch,1),ci_level);
inflect3_ci(ch,1:3)=get_ci2(inflect3_boot(:,ch,1),ci_level);
%inflect3 ci normalization search window of inflect3 is max(-150,elb_1(:,1)-150) to peak (see compute_onset_buildup_avg)
inflect3_ci(ch,4:5)=(inflect3_ci(ch,2:3)-inflect3_ci(ch,1))./mean(abs(max(-150,elb1_boot(:,ch,1)-150)-peak_boot(:,ch,1)))+inflect3_ci(ch,1);
%linear fit slopes
%fitslopes1_boot(:,ch,1)=get_fitangles(squeeze(fitparams1_boot(:,ch,1:2)));
%fitslopes1_boot(:,ch,2)=get_fitangles(squeeze(fitparams1_boot(:,ch,3:4)));
fitslopes1_boot(:,ch,1)=squeeze(fitparams1_boot(:,ch,2));
fitslopes1_boot(:,ch,2)=squeeze(fitparams1_boot(:,ch,4));
fitslopes1_1_ci(ch,:)=get_ci2(fitslopes1_boot(:,ch,1),ci_level);
fitslopes1_2_ci(ch,:)=get_ci2(fitslopes1_boot(:,ch,2),ci_level);
fitslopes1_diff_ci(ch,:)=get_ci2(fitslopes1_boot(:,ch,2)-fitslopes1_boot(:,ch,1),ci_level);
%[H1 p1]=get_testsignif(fitslopes1_boot(:,ch,1),fitslopes1_boot(:,ch,2),p_level);
tsignif_fitslopes1(ch,1)=get_testsignifci(fitslopes1_1_ci(ch,:),fitslopes1_2_ci(ch,:),0);
%for example [28] in paper
%tsignif_fitslopes1(ch,1)=get_testsignifci(fitslopes1_1_ci(ch,:),fitslopes1_2_ci(ch,:),-0.5);
% fitslopes2_boot(:,ch,1)=get_fitangles(squeeze(fitparams2_boot(:,ch,1:2)));
% fitslopes2_boot(:,ch,2)=get_fitangles(squeeze(fitparams2_boot(:,ch,3:4)));
% fitslopes2_1_ci(ch,:)=get_ci2(fitslopes2_boot(:,ch,1),ci_level);
% fitslopes2_2_ci(ch,:)=get_ci2(fitslopes2_boot(:,ch,2),ci_level);
%fitslopes3_boot(:,ch,1)=get_fitangles(squeeze(fitparams3_boot(:,ch,1:2)));
%fitslopes3_boot(:,ch,2)=get_fitangles(squeeze(fitparams3_boot(:,ch,3:4)));
fitslopes3_boot(:,ch,1)=squeeze(fitparams3_boot(:,ch,2));
fitslopes3_boot(:,ch,2)=squeeze(fitparams3_boot(:,ch,4));
fitslopes3_1_ci(ch,:)=get_ci2(fitslopes3_boot(:,ch,1),ci_level);
fitslopes3_2_ci(ch,:)=get_ci2(fitslopes3_boot(:,ch,2),ci_level);
fitslopes3_diff_ci(ch,:)=get_ci2(fitslopes3_boot(:,ch,2)-fitslopes3_boot(:,ch,1),ci_level);
%tsignif_fitslopes3(ch,1:2)=get_testsignif(fitslopes3_boot(:,ch,1),fitslopes3_boot(:,ch,2),p_level);
tsignif_fitslopes3(ch,1)=get_testsignifci(fitslopes3_1_ci(ch,:),fitslopes3_2_ci(ch,:),0);
%for example [28] in paper
%tsignif_fitslopes3(ch,1)=get_testsignifci(fitslopes3_1_ci(ch,:),fitslopes3_2_ci(ch,:),-0.5);
%ranksum tests between elb1 and inflect1
%tsignif_elb1_inflect1(ch,:)=get_testsignif(elb1_boot(:,ch,1),inflect1_boot(:,ch,1),p_level);
tsignif_elb1_inflect1(ch,:)=get_testsignifci(elb1_ci(ch,[1 4 5]),inflect1_ci(ch,[1 4 5]),0);
%to reproduce old results in power pointSC_onsetbuildup-VG-all-22-Feb-2018.pptx
%tsignif_elb1_inflect1(ch,:)=get_testsignifci(elb1_ci(ch,:),inflect1_ci(ch,:),0);
%for example [28] in paper
%tsignif_elb1_inflect1(ch,:)=get_testsignifci(elb1_ci(ch,1:3),inflect1_ci(ch,1:3),10);
%tsignif_elb1_inflect3(ch,:)=get_testsignif(elb1_boot(:,ch,1),inflect3_boot(:,ch,1),p_level);
end
%%
%%%%%%%%%%%%%
%plot onsets mean and ci
linetype_ci={'-' '--' '--','--','--'};
linewidth_ci=[4 2 2 2 2];
%peak mean and ci
figure(figtrialsboot)
color_ci={'k' 'k' 'k'};
for c=1:3
onset_plot=[];onset_plot(:,1)=peak_ci(:,c);
for ch=1:info.nchannels
if ~isnan(onset_plot(ch,1)) & round(onset_plot(ch,1))+info.aligntime <= size(trials_boot_avg,2)
onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%peak_avg(:,2);
end
end
plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
end
%elb1 mean and ci
figure(figtrialsboot)
color_ci={'b' 'b' 'b'};
for c=1:3
onset_plot=[];onset_plot(:,1)=elb1_ci(:,c);
for ch=1:info.nchannels
if ~isnan(onset_plot(ch,1))
onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%elb1_avg(:,2);
end
end
plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
end
% %elb2 mean and ci
% figure(figtrialsboot)
% color_ci={'g' 'g' 'g'};
% for c=1:3
% onset_plot=[];onset_plot(:,1)=elb2_ci(:,c);
% for ch=1:info.nchannels
% if ~isnan(onset_plot(ch,1))
% onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%elb2_avg(:,2);
% end
% end
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% end
%inflect1 mean and ci
figure(figtrialsboot)
color_ci={'r' 'r' 'r' 'r' 'r'};
for c=1:3
onset_plot=[];onset_plot(:,1)=inflect1_ci(:,c);
for ch=1:info.nchannels
if ~isnan(onset_plot(ch,1))
onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%inflect1_avg(:,2);
end
end
plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
end
% %inflect1 mean and ci
% figure(figtrialsboot2)
% color_ci={'r' 'r' 'r' 'r' 'r'};
% for c=1:3
% onset_plot=[];onset_plot(:,1)=inflect1_ci(:,c);
% for ch=1:info.nchannels
% if ~isnan(onset_plot(ch,1))
% onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%inflect1_avg(:,2);
% end
% end
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% end
% %inflect2 mean and ci
% figure(figtrialsboot2)
% color_ci={'m' 'm' 'm'};
% for c=1:3
% onset_plot=[];onset_plot(:,1)=inflect2_ci(:,c);
% for ch=1:info.nchannels
% if ~isnan(onset_plot(ch,1))
% onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%inflect2_avg(:,2);
% end
% end
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% end
%inflect3 mean and ci
figure(figtrialsboot3)
color_ci={'c' 'c' 'c'};
for c=1:3
onset_plot=[];onset_plot(:,1)=inflect3_ci(:,c);
for ch=1:info.nchannels
if ~isnan(onset_plot(ch,1))
onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%inflect3_avg(:,2);
end
end
plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
end
% %%
% %%%%%%%%%%%%%
% %plot stats for session
% %NOTE: here theshold on CI on both sides
% % %ci_level=0.8
% % peak_t=20;
% % elb1_t=30;
% % elb2_t=30;
% % inflect1_t=20;
% % inflect1n_t=1.2;%1.3
% % inflect2_t=50;%30;
% % inflect3_t=20;
%
% %ci_level=0.95
% peak_t=20;
% elb1_t=40;
% elb1n_t=0.15;
% elb2_t=40;
% inflect1_t=20;
% inflect1n_t=0.15;%1.3
% inflect2_t=50;%30;
% inflect3_t=20;
% inflect3n_t=0.15;
%
% % peak_t=inf;
% % elb1_t=inf;
% % elb2_t=inf;
% % inflect1_t=inf;
% % inflect1n_t=inf;
% % inflect2_t=inf;%30;
% % inflect3_t=inf;
%
% % peak_t=0;
% % elb1_t=0;
% % elb2_t=0;
% % inflect1_t=0;
% % inflect1n_t=0;
% % inflect2_t=0;
% % inflect3_t=0;
%
%
% %plot ci of onsets
% figelbs=figure('Position',[1 100 scrsz(3) scrsz(4)-500]);
% hold on;
% %peak
% subplot(1,7,1);hold on;
% errorbar(1:info.nchannels,zeros(16,1),abs(peak_ci(:,2)-peak_ci(:,1)),abs(peak_ci(:,3)-peak_ci(:,1)));
% h=line([0 17],[peak_t peak_t]);set(h,'color','r');
% h=line([0 17],[-peak_t -peak_t]);set(h,'color','r');
% grid minor;axis([0 17 -100 100]);
% xlabel('Channel');ylabel('CI (ms)')
% title('peak')
% %elb1
% subplot(1,7,2);hold on;
% errorbar(1:info.nchannels,zeros(16,1),abs(elb1_ci(:,2)-elb1_ci(:,1)),abs(elb1_ci(:,3)-elb1_ci(:,1)));
% h=line([0 17],[elb1_t elb1_t]);set(h,'color','r');
% h=line([0 17],[-elb1_t -elb1_t]);set(h,'color','r');
% grid minor;axis([0 17 -100 100]);
% xlabel('Channel');ylabel('CI (ms)')
% title('elb1')
% %elb1 normalized
% subplot(1,7,3);hold on;
% hdl_e=errorbar(1:info.nchannels,zeros(16,1),abs(elb1_ci(:,4)-elb1_ci(:,1)),abs(elb1_ci(:,5)-elb1_ci(:,1)));
% set(hdl_e,'color','m')
% h=line([0 17],[elb1n_t elb1n_t]);set(h,'color','r');
% h=line([0 17],[-elb1n_t -elb1n_t]);set(h,'color','r');
% grid minor;axis([0 17 -0.5 0.5]);
% xlabel('Channel');ylabel('CI (ms)')
% title('elb1 normalized')
% % %elb2
% % subplot(1,6,4);hold on;
% % errorbar(1:info.nchannels,zeros(16,1),abs(elb2_ci(:,2)-elb2_ci(:,1)),abs(elb2_ci(:,3)-elb2_ci(:,1)));
% % h=line([0 17],[elb2_t elb2_t]);set(h,'color','r');
% % h=line([0 17],[-elb2_t -elb2_t]);set(h,'color','r');
% % grid minor;axis([0 17 -100 100]);
% % xlabel('Channel');ylabel('CI (ms)')
% % title('elb2')
% %inflect1
% subplot(1,7,4);hold on;
% errorbar(1:info.nchannels,zeros(16,1),abs(inflect1_ci(:,2)-inflect1_ci(:,1)),abs(inflect1_ci(:,3)-inflect1_ci(:,1)));
% h=line([0 17],[inflect1_t inflect1_t]);set(h,'color','r');
% h=line([0 17],[-inflect1_t -inflect1_t]);set(h,'color','r');
% grid minor;axis([0 17 -100 100]);
% xlabel('Channel');ylabel('CI (ms)')
% title('inflect1')
% %inflect1 normalized
% subplot(1,7,5);hold on;
% hdl_e=errorbar(1:info.nchannels,zeros(16,1),abs(inflect1_ci(:,4)-inflect1_ci(:,1)),abs(inflect1_ci(:,5)-inflect1_ci(:,1)));
% set(hdl_e,'color','m')
% h=line([0 17],[inflect1n_t inflect1n_t]);set(h,'color','r');
% h=line([0 17],[-inflect1n_t -inflect1n_t]);set(h,'color','r');
% grid minor;axis([0 17 -0.5 0.5]);
% xlabel('Channel');ylabel('CI (ms)')
% title('inflect1 normalized')
% % %inflect2
% % subplot(1,6,7);hold on;
% % errorbar(1:info.nchannels,zeros(16,1),abs(inflect2_ci(:,2)-inflect2_ci(:,1)),abs(inflect2_ci(:,3)-inflect2_ci(:,1)));
% % h=line([0 17],[inflect2_t inflect2_t]);set(h,'color','r');
% % h=line([0 17],[-inflect2_t -inflect2_t]);set(h,'color','r');
% % grid minor;axis([0 17 -100 100]);
% % xlabel('Channel');ylabel('CI (ms)')
% % title('inflect2')
% %inflect3
% subplot(1,7,6);hold on;
% errorbar(1:info.nchannels,zeros(16,1),abs(inflect3_ci(:,2)-inflect3_ci(:,1)),abs(inflect3_ci(:,3)-inflect3_ci(:,1)));
% h=line([0 17],[inflect3_t inflect3_t]);set(h,'color','r');
% h=line([0 17],[-inflect3_t -inflect3_t]);set(h,'color','r');
% grid minor;axis([0 17 -100 100]);
% xlabel('Channel');ylabel('CI (ms)')
% title('inflect3')
% %inflect3 normalized
% subplot(1,7,7);hold on;
% hdl_e=errorbar(1:info.nchannels,zeros(16,1),abs(inflect3_ci(:,4)-inflect3_ci(:,1)),abs(inflect3_ci(:,5)-inflect3_ci(:,1)));
% set(hdl_e,'color','m')
% h=line([0 17],[inflect3n_t inflect3n_t]);set(h,'color','r');
% h=line([0 17],[-inflect3n_t -inflect3n_t]);set(h,'color','r');
% grid minor;axis([0 17 -0.5 0.5]);
% xlabel('Channel');ylabel('CI (ms)')
% title('inflect3 normalized')
%
% %pause
%%
%%%%%%%%%%%%%
%plot stats for session
%NOTE: here threshold on range of ci (sum of both sides)
%ci_level=0.95
peak_t=40;
elb1_t=80;
%elb1n_t=0.4;%for results
elb1n_t=0.6;%0.4;%0.6;%0.3;0.45;
%for example [28 ]in paper
%elb1n_t=0.4 %0.5;%0.6;%0.3;0.45;
elb2_t=80;
inflect1_t=40;
inflect1n_t=0.5;%0.6;%0.3;0.45;%1.3
inflect1adiff_t=25;
inflect2_t=100;%30;
inflect3_t=40;
inflect3n_t=0.5;%0.6;%0.3;0.45;
inflect3adiff_t=25;
% peak_t=inf;
% elb1_t=inf;
% elb1n_t=inf;
% elb2_t=inf;
% inflect1_t=inf;
% inflect1adiff_t=-inf;
% inflect1n_t=inf;
% inflect2_t=inf;%30;
% inflect3_t=inf;
% inflect3n_t=inf;
% inflect3adiff_t=-inf;
% peak_t=0;
% elb1_t=0;
% elb2_t=0;
% inflect1_t=0;
% inflect1n_t=0;
% inflect2_t=0;
% inflect3_t=0;
%plot ci of onsets
figelbs=figure('Position',[1 100 scrsz(3) scrsz(4)-500]);
hold on;
%peak
subplot(1,6,1);hold on;
errorbar(1:info.nchannels,zeros(16,1),zeros(info.nchannels,1),abs(peak_ci(:,2)-peak_ci(:,3)));
h=line([0 17],[peak_t peak_t]);set(h,'color','r');
grid minor;axis([0 17 0 200]);
xlabel('Channel');ylabel('CI (ms)')
title('peak')
% %elb1
% subplot(1,7,2);hold on;
% errorbar(1:info.nchannels,zeros(16,1),zeros(info.nchannels,1),abs(elb1_ci(:,2)-elb1_ci(:,3)));
% h=line([0 17],[elb1_t elb1_t]);set(h,'color','r');
% grid minor;axis([0 17 0 200]);
% xlabel('Channel');ylabel('CI (ms)')
% title('elb1')
%elb1 normalized
subplot(1,6,2);hold on;
hdl_e=errorbar(1:info.nchannels,zeros(16,1),zeros(info.nchannels,1),abs(elb1_ci(:,4)-elb1_ci(:,5)));
set(hdl_e,'color','m')
h=line([0 17],[elb1n_t elb1n_t]);set(h,'color','r');
grid minor;axis([0 17 0 1]);
xlabel('Channel');ylabel('CI (ms)')
title('elb1 normalized')
% %elb2
% subplot(1,6,4);hold on;
% errorbar(1:info.nchannels,zeros(16,1),zeros(info.nchannels,1),abs(elb2_ci(:,2)-elb2_ci(:,3)));
% h=line([0 17],[elb2_t elb2_t]);set(h,'color','r');
% grid minor;axis([0 17 0 200]);
% xlabel('Channel');ylabel('CI (ms)')
% title('elb2')
% %inflect1
% subplot(1,7,4);hold on;
% errorbar(1:info.nchannels,zeros(16,1),zeros(info.nchannels,1),abs(inflect1_ci(:,2)-inflect1_ci(:,3)));
% h=line([0 17],[inflect1_t inflect1_t]);set(h,'color','r');
% grid minor;axis([0 17 0 200]);
% xlabel('Channel');ylabel('CI (ms)')
% title('inflect1')
%inflect1 normalized
subplot(1,6,3);hold on;
hdl_e=errorbar(1:info.nchannels,zeros(16,1),zeros(info.nchannels,1),abs(inflect1_ci(:,4)-inflect1_ci(:,5)));
set(hdl_e,'color','m')
h=line([0 17],[inflect1n_t inflect1n_t]);set(h,'color','r');
grid minor;axis([0 17 0 1]);
xlabel('Channel');ylabel('CI (ms)')
title('inflect1 normalized')
% %inflect2
% subplot(1,6,7);hold on;
% errorbar(1:info.nchannels,zeros(16,1),zeros(info.nchannels,1),abs(inflect2_ci(:,2)-inflect2_ci(:,3)));
% h=line([0 17],[inflect2_t inflect2_t]);set(h,'color','r');
% grid minor;axis([0 17 0 200]);
% xlabel('Channel');ylabel('CI (ms)')
% title('inflect2')
% %inflect3
% subplot(1,7,6);hold on;
% errorbar(1:info.nchannels,zeros(16,1),zeros(info.nchannels,1),abs(inflect3_ci(:,2)-inflect3_ci(:,3)));
% h=line([0 17],[inflect3_t inflect3_t]);set(h,'color','r');
% grid minor;axis([0 17 0 200]);
% xlabel('Channel');ylabel('CI (ms)')
% title('inflect3')
%inflect3 normalized
subplot(1,6,5);hold on;
hdl_e=errorbar(1:info.nchannels,zeros(16,1),zeros(info.nchannels,1),abs(inflect3_ci(:,4)-inflect3_ci(:,5)));
set(hdl_e,'color','m')
h=line([0 17],[inflect3n_t inflect3n_t]);set(h,'color','r');
grid minor;axis([0 17 0 1]);
xlabel('Channel');ylabel('CI (ms)')
title('inflect3 normalized')
%plot slopes of inflections
%figslopes=figure('Position',[1 100 scrsz(3) scrsz(4)-500]);
%hold on;
%inflect1 slopes
subplot(1,6,4);hold on;
hdl_e=errorbar(1:info.nchannels,fitslopes1_1_ci(:,1),fitslopes1_1_ci(:,3)-fitslopes1_1_ci(:,1),fitslopes1_1_ci(:,2)-fitslopes1_1_ci(:,1));
set(hdl_e,'color','b')
hdl_e=errorbar(1:info.nchannels,fitslopes1_2_ci(:,1),fitslopes1_2_ci(:,3)-fitslopes1_2_ci(:,1),fitslopes1_2_ci(:,2)-fitslopes1_2_ci(:,1));
set(hdl_e,'color','r')
h=line([0 17],[0 0]);set(h,'color','k');
grid minor;axis([0 17 -1 10]);
xlabel('Channel');ylabel('slopes+CI (spk/s^2)')
title('inflect1 slopes')
% %inflect1 diff slopes
% subplot(1,4,2);hold on;
% hdl_e=errorbar(1:info.nchannels,fitslopes1_diff_ci(:,1),fitslopes1_diff_ci(:,2),fitslopes1_diff_ci(:,3));
% set(hdl_e,'color','b')
% h=line([0 17],[0 0]);set(h,'color','k');
% h=line([0 17],[inflect1adiff_t inflect1adiff_t]);set(h,'color','r');
% grid minor;axis([0 17 -10 10]);
% xlabel('Channel');ylabel('slopes+CI (spk/s^2)')
% title('inflect1 diff slopes')
%inflect3 slopes
subplot(1,6,6);hold on;
hdl_e=errorbar(1:info.nchannels,fitslopes3_1_ci(:,1),fitslopes3_1_ci(:,3)-fitslopes3_1_ci(:,1),fitslopes3_1_ci(:,2)-fitslopes3_1_ci(:,1));
set(hdl_e,'color','b')
hdl_e=errorbar(1:info.nchannels,fitslopes3_2_ci(:,1),fitslopes3_2_ci(:,3)-fitslopes3_2_ci(:,1),fitslopes3_2_ci(:,2)-fitslopes3_2_ci(:,1));
set(hdl_e,'color','r')
h=line([0 17],[0 0]);set(h,'color','k');
grid minor;axis([0 17 -1 10]);
xlabel('Channel');ylabel('slopes+CI (spk/s^2)')
title('inflect3 slopes')
% %inflect3 diff slopes
% subplot(1,4,4);hold on;
% hdl_e=errorbar(1:info.nchannels,fitslopes3_diff_ci(:,1),fitslopes3_diff_ci(:,2),fitslopes3_diff_ci(:,3));
% set(hdl_e,'color','b')
% h=line([0 17],[0 0]);set(h,'color','k');
% h=line([0 17],[inflect3adiff_t inflect3adiff_t]);set(h,'color','r');
% grid minor;axis([0 17 -10 10]);
% xlabel('Channel');ylabel('slopes+CI (spk/s^2)')
% title('inflect3 diff slopes')
%plot regression between CI and slopes diff
figciadiff=figure;
subplot(1,2,1);hold on;
%regression 1
xr=fitslopes1_diff_ci(:,1);
yr=abs(inflect1_ci(:,4)-inflect1_ci(:,5));
x_thresh=inflect1adiff_t;
y_thresh=inflect1n_t;
nnan=find(~isnan(xr) & ~isnan(yr));
xr=xr(nnan);yr=yr(nnan);
[p_fit rsq_fit yr_fit]=get_regressioncoefs(xr,yr,1);
plot(xr,yr,'ok')
plot(xr,yr_fit,'r-')
%h=line([x_thresh x_thresh],[0 max(yr)+0.1]);set(h,'color','k','linestyle','--');
h=line([0 max(xr)+1],[y_thresh y_thresh]);set(h,'color','k','linestyle','--');
axis([0 max(xr)+1 0 max(yr)+0.1])
text(max(xr)-1,max(yr),['r2=' num2str(round(rsq_fit,2))])
ylabel('CI normalized (ms)');xlabel('slopes diff (spk/s^2)');
title('inflect 1')
subplot(1,2,2);hold on;
%regression 3
xr=fitslopes3_diff_ci(:,1);
yr=abs(inflect3_ci(:,4)-inflect3_ci(:,5));
x_thresh=inflect3adiff_t;
y_thresh=inflect3n_t;
nnan=find(~isnan(xr) & ~isnan(yr));
xr=xr(nnan);yr=yr(nnan);
[p_fit rsq_fit yr_fit]=get_regressioncoefs(xr,yr,1);
plot(xr,yr,'ok')
plot(xr,yr_fit,'r-')
%h=line([x_thresh x_thresh],[0 max(yr)+0.1]);set(h,'color','k','linestyle','--');
h=line([0 max(xr)+1],[y_thresh y_thresh]);set(h,'color','k','linestyle','--');
axis([0 max(xr)+1 0 max(yr)+0.1])
text(max(xr)-1,max(yr),['r2=' num2str(round(rsq_fit,2))])
ylabel('CI normalized (ms)');xlabel('slopes diff (spk/s^2)');
title('inflect 3')
tsignif_fitslopes1'
tsignif_fitslopes3'
%pause
% %%
% %%%%%%%%%%%%%
% %save in powerpoint
% if savepptx,
% savetopptx(figtrialsboot,file,figtype,{info.datafile ;' Elbow 1 and 2'});
% savetopptx(figtrialsboot2,file,figtype,{info.datafile ;' Inflection 1 and 2'});
% %savetopptx(figtrialsboot3,file,figtype,{info.datafile ;' Inflection 3'});
% savetopptx(figelbs,file,figtype,{info.datafile ;' CI of onsets and slopes'});
% savetopptx(figciadiff,file,figtype,{info.datafile ;' Regression CI vs. slopes diff'});
%
% end
%%
% %%%%%%%%%%%%%
% %onsets selection by threshold on both side of ci
% %peak
% peak_aux=(sum(abs(peak_ci(:,2:3)-peak_ci(:,1))<peak_t,2)==2);
% peak_sel=peak_ci(:,1:3);
% peak_sel(find(peak_aux==0),:)=nan;
% % %elb1
% % elb1_aux=(sum(abs(elb1_ci(:,2:3)-elb1_ci(:,1))<elb1_t,2)==2);
% % elb1_sel=elb1_ci(:,1:3);
% % elb1_sel(find(elb1_aux==0),:)=nan;
% %elb1 normalized
% elb1_aux=(sum(abs(elb1_ci(:,4:5)-elb1_ci(:,1))<elb1n_t,2)==2);
% elb1_sel=elb1_ci(:,[1 4 5]);
% elb1_sel(find(elb1_aux==0),:)=nan;
% %elb2
% elb2_aux=(sum(abs(elb2_ci(:,2:3)-elb2_ci(:,1))<elb2_t,2)==2);
% elb2_sel=elb2_ci(:,1:3);
% elb2_sel(find(elb2_aux==0),:)=nan;
% % %inflect1
% % inflect1_aux=(sum(abs(inflect1_ci(:,2:3)-inflect1_ci(:,1))<inflect1_t,2)==2);
% % inflect1_sel=inflect1_ci(:,1:3);
% % inflect1_sel(find(inflect1_aux==0),:)=nan;
% %inflect1 normalized
% inflect1_aux=(sum(abs(inflect1_ci(:,4:5)-inflect1_ci(:,1))<inflect1n_t,2)==2);
% inflect1_sel=inflect1_ci(:,[1 4 5]);
% inflect1_sel(find(inflect1_aux==0),:)=nan;
% %inflect2
% inflect2_aux=(sum(abs(inflect2_ci(:,2:3)-inflect2_ci(:,1))<inflect2_t,2)==2);
% inflect2_sel=inflect2_ci(:,1:3);
% inflect2_sel(find(inflect2_aux==0),:)=nan;
% % %inflect3
% % inflect3_aux=(sum(abs(inflect3_ci(:,2:3)-inflect3_ci(:,1))<inflect3_t,2)==2);
% % inflect3_sel=inflect3_ci(:,1:3);
% % inflect3_sel(find(inflect3_aux==0),:)=nan;
% %inflect3 normalized
% inflect3_aux=(sum(abs(inflect3_ci(:,4:5)-inflect3_ci(:,1))<inflect3n_t,2)==2);
% inflect3_sel=inflect3_ci(:,[1 4 5]);
% inflect3_sel(find(inflect3_aux==0),:)=nan;
%onsets selection by threshold on range of ci
%peak
peak_aux=abs(peak_ci(:,2)-peak_ci(:,3))<peak_t;
peak_sel=peak_ci(:,1:3);
peak_sel(find(peak_aux==0),:)=nan;
%elb1
elb1_thresh=abs(elb1_ci(:,4)-elb1_ci(:,5))<elb1n_t;
elb1_sel=elb1_ci(:,[1 4 5]);
elb1_sel(find(elb1_thresh==0),:)=nan;
%elb2
elb2_sel=nan(16,3);
%inflect1
%inflect1_thresh=abs(inflect1_ci(:,4)-inflect1_ci(:,5))<inflect1n_t;
%inflect1_thresh=abs(inflect1_ci(:,4)-inflect1_ci(:,5))<inflect1n_t & fitslopes1_diff_ci(:,1)>inflect1adiff_t;
inflect1_thresh=tsignif_fitslopes1;
inflect1_sel=inflect1_ci(:,[1 4 5]);
inflect1_sel(find(inflect1_thresh==0),:)=nan;
%elb2
inflect2_sel=nan(16,3);
%inflect3
%inflect3_thresh=abs(inflect3_ci(:,4)-inflect3_ci(:,5))<inflect3n_t;
%inflect3_thresh=abs(inflect3_ci(:,4)-inflect3_ci(:,5))<inflect3n_t & fitslopes3_diff_ci(:,1)>inflect3adiff_t;
inflect3_thresh=tsignif_fitslopes3;
inflect3_sel=inflect3_ci(:,[1 4 5]);
inflect3_sel(find(inflect3_thresh==0),:)=nan;
% %plot selected onsets
% linetype_ci={'-' '--' '--'};
% linewidth_ci=[4 2 2];
% % color_ci={'k' 'k' 'k'};
% % %peak mean and ci
% % figure(figtrialsboot)
% % for c=1:3
% % onset_plot=[];onset_plot(:,1)=peak_sel(:,c);
% % for ch=1:info.nchannels
% % if ~isnan(onset_plot(ch,1))
% % onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%peak_avg(:,2);
% % end
% % end
% % plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% % end
% %elb1 mean and ci
% figure(figtrialsboot)
% color_ci={'k' 'k' 'k'};
% for c=1:3
% onset_plot=[];onset_plot(:,1)=elb1_sel(:,c);
% for ch=1:info.nchannels
% if ~isnan(onset_plot(ch,1))
% onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%elb1_avg(:,2);
% end
% end
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% end
% % %elb2 mean and ci
% % figure(figtrialsboot)
% % for c=1:3
% % onset_plot=[];onset_plot(:,1)=elb2_sel(:,c);
% % for ch=1:info.nchannels
% % if ~isnan(onset_plot(ch,1))
% % onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%elb2_avg(:,2);
% % end
% % end
% % plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% % end
% %inflect1 mean and ci
% figure(figtrialsboot)
% for c=1:3
% onset_plot=[];onset_plot(:,1)=inflect1_sel(:,c);
% for ch=1:info.nchannels
% if ~isnan(onset_plot(ch,1))
% onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%inflect1_avg(:,2);
% end
% end
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% end
% %inflect1 mean and ci
% figure(figtrialsboot2)
% for c=1:3
% onset_plot=[];onset_plot(:,1)=inflect1_sel(:,c);
% for ch=1:info.nchannels
% if ~isnan(onset_plot(ch,1))
% onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%inflect1_avg(:,2);
% end
% end
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% end
% %inflect2 mean and ci
% figure(figtrialsboot2)
% for c=1:3
% onset_plot=[];onset_plot(:,1)=inflect2_sel(:,c);
% for ch=1:info.nchannels
% if ~isnan(onset_plot(ch,1))
% onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%inflect2_avg(:,2);
% end
% end
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% end
% %inflect3 mean and ci
% figure(figtrialsboot3)
% for c=1:3
% onset_plot=[];onset_plot(:,1)=inflect3_sel(:,c);
% for ch=1:info.nchannels
% if ~isnan(onset_plot(ch,1))
% onset_plot(ch,2)=trials_boot_avg(ch,round(onset_plot(ch,1))+info.aligntime);%inflect3_avg(:,2);
% end
% end
% plot_events_ch(onset_plot.*[burst_bsignif ; burst_bsignif]',[],vshift_spk,range_spk,info,hdlfig,'n',linetype_ci{c},linewidth_ci(c),color_ci{c});
% end
%
%%
%%%%%%%%%%%%%
%classification accum/burst
%selection between elb1/inflect1/inflect3
% %threshold each sides separately
% %elb1_thresh=(sum(abs(elb1_ci(:,2:3)-elb1_ci(:,1))<elb1_t,2))>=1;
% %inflect1_thresh=(sum(abs(inflect1_ci(:,2:3)-inflect1_ci(:,1))<inflect1_t,2))>=1;
% %inflect3_thresh=(sum(abs(inflect3_ci(:,2:3)-inflect3_ci(:,1))<inflect3_t,2))>=1;
% elb1_thresh=(sum(abs(elb1_ci(:,4:5)-elb1_ci(:,1))<elb1n_t,2))>=1;
% inflect1_thresh=(sum(abs(inflect1_ci(:,4:5)-inflect1_ci(:,1))<inflect1n_t,2))>=1;
% inflect3_thresh=(sum(abs(inflect3_ci(:,4:5)-inflect3_ci(:,1))<inflect3n_t,2))>=1;
% %threshold on range of CI
% elb1_thresh=abs(elb1_ci(:,4)-elb1_ci(:,5))<elb1n_t;
% inflect1_thresh=abs(inflect1_ci(:,4)-inflect1_ci(:,5))<inflect1n_t;
% inflect3_thresh=abs(inflect3_ci(:,4)-inflect3_ci(:,5))<inflect3n_t;
classif_t=-50
accum_onset=nan(info.nchannels,2);burst_onset=nan(info.nchannels,2);
inflect31_onset=nan(info.nchannels,2);inflect32_onset=nan(info.nchannels,2);
scat_01=nan(info.nchannels,2);
scat_10=nan(info.nchannels,2);
scat_10_3=nan(info.nchannels,2);
scat_11=nan(info.nchannels,2);
scat_11_3=nan(info.nchannels,2);
for ch=1:info.nchannels
if elb1_thresh(ch)~=1 & inflect1_thresh(ch)==1
%classification of inflect1
if inflect1_ci(ch,1)>classif_t
burst_onset(ch,1)=inflect1_ci(ch,1);
burst_onset(ch,2)=trials_boot_avg(ch,round(burst_onset(ch,1))+info.aligntime);
else
accum_onset(ch,1)=inflect1_ci(ch,1);
accum_onset(ch,2)=trials_boot_avg(ch,round(accum_onset(ch,1))+info.aligntime);
end
%for scatter plot
scat_01(ch,1:2)=[0 inflect1_ci(ch,1)];
display(['ch=' num2str(ch) ' elb1~=1 inflect1=1'])
display('This condition happens sometimes!')
%pause
elseif elb1_thresh(ch)==1 & inflect1_thresh(ch)~=1
%NOTE: optimally replace classif_t boundary by progressive increase
%of the significance of the slopes difference for inflect3
%classification of elb1
if elb1_ci(ch,1)<classif_t
accum_onset(ch,1)=elb1_ci(ch,1);
accum_onset(ch,2)=trials_boot_avg(ch,round(accum_onset(ch,1))+info.aligntime);
%for scatter plot
scat_10(ch,1:2)=[elb1_ci(ch,1) 0];
display(['ch=' num2str(ch) ' elb1=1 inflect1~=1 elb1<classif_t'])
display('elb1 (<classif_t):')
elb1_ci(ch,1)
elb1_ci(ch,1)<classif_t
%pause
elseif elb1_ci(ch,1)>classif_t & inflect3_thresh(ch)==1
if inflect3_ci(ch,1)>classif_t