-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrosscor.m
1821 lines (1617 loc) · 54.9 KB
/
crosscor.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 crosscor(action)
%*********************************************************************
% Ian's Surface Plots for XCor Raw Data sets
%
% This reads SMR / TXT files containing spike times, computes
% the cross-correlogram for many variables, and can generate surface
% plots of a defined portion of the cross-correlogram function
%
%*********************************************************************
global TimeInterval
global PlotType CMap ShadingType
global Lighting LightAdd
global SmoothType SmoothValue
global xdata xv
global george
global loop
global corrline
global datatype
global slope
global rerun
global hw
if nargin<1;
action='Initialize';
end
switch(action)
%-------------------------------------------------------------------
case 'Initialize' %assuming we have just started
%-------------------------------------------------------------------
crosscorfig %load our GUI
xv.matlabroot=regexprep(matlabroot,'Program files','Progra~1','ignorecase');
version='Cross Correlation Analysis: V3.1a';
if exist('c:\xdata.mat','file'); delete('c:\xdata.mat'); end
if exist('c:\crosstemp','file');delete('c:\crosstemp'); end
figpos(2); %position the figure
set(gcf,'Name', version)
set(gh('RatioValue'),'String',{'Don''t Use';'25ms Ratio';'50ms Ratio';'100ms Ratio'});
set(gh('IntBox'),'String',nums2strs(0.1:0.05:1));
set(gh('IntBox'),'Value',4)
set(gh('ShuffleNumber'),'String','trials-1');
xv.StartBin=-5; xv.EndBin=5;
xv.BinWidth=4; xv.Window=200;
xv.FromTime=0; xv.ToTime=Inf;
xv.StartTrial=1; xv.EndTrial=inf;
xv.firstunit=1; xv.secondunit=2;
xv.HeldVariable=3; xv.HeldValue=1;
xv.Shuffles=0; xv.pValue=0.05;
TimeInterval=500;
george=1;
PlotType='CheckerBoard';
ShadingType='interp';
Lighting='phong';
SmoothType='none';
SmoothValue=5;
CMap='jet';
datatype='';
slope=0;
hw=0;
xdata=[];
rerun='no';
set(gcf,'DefaultLineLineWidth',1.5);
set(gcf,'DefaultAxesLineWidth',1.5);
set(gca,'Layer','top'); %ticks go over data
set(gcf,'DefaultAxesTickDir','out'); %get ticks going out
set(0,'defaultaxesfontname','Georgia');
set(0,'defaulttextfontname','Georgia');
set(0,'defaulttextfontsize',8);
%-------------------------------------------------------------------
case 'Load'
%-------------------------------------------------------------------
set(gh('RatioValue'),'Value',1);
cla;
set(gca,'Tag','XCorAxis');
if strcmp(rerun,'yes') %see if we have to reload the data or not
%--Initial Parameters
hw=0;
slope=0;
file=xdata.filename;
xdata=[];
[p,basefilename,e]=fileparts(file);
%--Reloads from temporary file
rerun='no';
xdata.filetype = 'txt';
xdata.meta=loadvstext(file);
txtcomment=textread(strcat(p,'\',basefilename,'.cmt'),'%s','delimiter','\n','whitespace','');
txtprotocol=textread(strcat(p,'\',basefilename,'.prt'),'%s','delimiter','\n','whitespace','');
else
%--Initial Parameters
xdata=[];
% xv.StartTrial=1;
% xv.EndTrial=inf;
% set(gh('StartTrial'),'String','1');
% set(gh('EndTrial'),'String','inf');
hw=0;
slope=0;
%--Get filename and run appropriate frogbit script
[fn,pn]=uigetfile({'*.smr;*.txt;*.doc','All Spikes Filetypes (*.smr *.txt *.doc)';'*.smr','VS RAW DATA File (SMR)';'*.txt','VSX Output File (TXT)';'*.doc','XCor Output File (DOC)'},'Select File Typeto Load:');
if isequal(fn,0)|isequal(pn,0);set(gh('LoadText'),'String','No Data Loaded');errordlg('No File Selected or Found!');error('File not selected');end
[p,basefilename,e]=fileparts([pn fn]);
if regexpi(e,'\.smr')
if isdir([p '\' basefilename])
cd('c:\');
disp('Deleted existing directory...');
rmdir([p '\' basefilename],'s');
cd(p);
end
s=dos([xv.matlabroot,'\user\various\vsx\vsx.exe ',pn,fn]);
pn2 = fn(1:find(fn(:)=='.')-1);
s=dos(['dir ',pn,pn2]);
if s~=0; error('Sorry VSX cannot load the data!!! Make sure files do not have the read-only attribute set...'); end
xdata.filetype = 'smr';
xdata.meta=loadvstext([pn basefilename '\' basefilename '.txt']);
txtcomment=textread(strcat(pn,basefilename,'\',basefilename,'.cmt'),'%s','delimiter','\n','whitespace','');
txtprotocol=textread(strcat(pn,basefilename,'\',basefilename,'.prt'),'%s','delimiter','\n','whitespace','');
elseif strcmpi(e,'.txt')
xdata.filetype = 'txt';
xdata.meta=loadvstext([pn,fn]);
[p,basefilename,e]=fileparts([pn fn]);
txtcomment=textread(strcat(p,'\',basefilename,'.cmt'),'%s','delimiter','\n','whitespace','');
txtprotocol=textread(strcat(p,'\',basefilename,'.prt'),'%s','delimiter','\n','whitespace','');
elseif strcmpi(e,'.doc')
errordlg('Sorry, .doc files are an old format not safe to use, please use the .SMR!');
error('Sorry, .doc files are an old format not safe to use, please use the .SMR!');
else
errordlg('Sorry, unsupported file type loaded!')
error('File selection error')
end
end
[p,basefilename,e]=fileparts(xdata.meta.filename); %seperate out the file from the path
xdata.info=['===============PROTOCOL================';txtprotocol(2:end);'===============COMMENTS================';txtcomment(2:end)];
cd(p); %change to the directory where all the spike time files live
xdata.meta.filename(xdata.meta.filename=='\')='/'; %stops annoying TeX interpertation errors
t=find(xdata.meta.filename=='/');
xdata.runname=xdata.meta.filename((t(end-2))+1:t(end)); %we make a pretty name for titles
xdata.numvars=xdata.meta.numvars;
xdata.protocol.name=xdata.meta.protocol;
xdata.protocol.desc=xdata.meta.description;
xdata.protocol.filecomm=xdata.meta.comments;
xdata.protocol.date=xdata.meta.date;
xdata.repeats=xdata.meta.repeats;
if strcmp(xdata.filetype,'smr') || strcmp(xdata.filetype,'txt')
xdata.cycles=xdata.meta.cycles;
xdata.trialtime=xdata.meta.trialtime;
xdata.modtime=xdata.meta.modtime;
if isfield(xdata.meta,'tempfreq')
xdata.tempfreq=xdata.meta.tempfreq;
else
xdata.tempfreq=[];
end
end
%-Info from GUI
xdata.cellone=xv.firstunit;
xdata.celltwo=xv.secondunit;
%-Initialise File indexes
firstnumber=0; lastnumber=1;
switch xdata.numvars
case 0 %this means we have no variables
%--This section extracts variable info and sets up the data structure
firstnumber=min(xdata.meta.matrix(:,1)); %tells us the first and last file to load
lastnumber=max(xdata.meta.matrix(:,1));
%--Set Up the Struct Matrix to hold all the cross correlograms and header data
clear slope;
xdata.filename=xdata.meta.filename;
xdata.xtitle='';
xdata.xvalues=[];
xdata.xrange=1;
xdata.ytitle='';
xdata.yvalues=[];
xdata.yrange=1;
xdata.ztitle='';
xdata.zvalues=[];
xdata.zrange=1;
xdata.matrix=[];
xdata.xcorindex=0;
xdata.xcor.values=0;
xdata.xcor.time=0;
case 1
firstnumber=min(xdata.meta.matrix(:,1)); %tells us the first and last file to load
lastnumber=max(xdata.meta.matrix(:,1));
% This section extracts variable info and sets up the data structure
xdata.filename=xdata.meta.filename;
xdata.xtitle=regexprep(xdata.meta.var{1}.title,'w\\o','with O');
xdata.xrange=xdata.meta.var{1}.range;
xdata.xvalues=xdata.meta.var{1}.values;
xdata.ytitle='';
xdata.yvalues=[];
xdata.yrange=1;
xdata.ztitle='';
xdata.zvalues=[];
xdata.zrange=1;
xdata.matrix=[xdata.xrange];
xdata.xcorindex=0;
xdata.xcor.values=0;
xdata.xcor.time=0;
case 2 %2 variables
set(gh('SmoothingMenu'),'String',{'none';'cubic';'v4';'linear';'nearest'});
firstnumber=min(xdata.meta.matrix(:,1)); %tells us the first and last file to load
lastnumber=max(xdata.meta.matrix(:,1));
%--Set Up the Struct Matrix to hold all the cross correlograms and header data
xdata.filename=xdata.meta.filename;
xdata.xtitle=regexprep(xdata.meta.var{1}.title,'w\\ o','with O');
xdata.xrange=xdata.meta.var{1}.range;
xdata.xvalues=xdata.meta.var{1}.values;
xdata.ytitle=xdata.meta.var{2}.title;
xdata.yrange=xdata.meta.var{2}.range;
xdata.yvalues=xdata.meta.var{2}.values;
xdata.ztitle='';
xdata.zvalues=[];
xdata.zrange=1;
xdata.matrix=zeros(xdata.yrange,xdata.xrange);
xdata.xcorindex=0;
xdata.xcor.values=0;
xdata.xcor.time=0;
case 3
set(gh('SmoothingMenu'),'String',{'none';'cubic';'v4';'linear';'nearest'});
% this section juggles all the variables around for selection
x=header(3,find(header(3,:) == ':')+1:end);
xv.heldvar(1).name=x(find(x(1,:)~=' ')); %this strips spaces
x=str2num(header(4,find(header(4,:) == ':')+1:end));
xv.heldvar(1).range=x;
x=str2num(header(5,find(header(5,:) == ':')+1:end));
xv.heldvar(1).values=x;
x=header(6,find(header(6,:) == ':')+1:end);
xv.heldvar(2).name=x(find(x(1,:)~=' '));
x=str2num(header(7,find(header(7,:) == ':')+1:end));
xv.heldvar(2).range=x;
x=str2num(header(8,find(header(8,:) == ':')+1:end));
xv.heldvar(2).values=x;
x=header(9,find(header(9,:) == ':')+1:end);
xv.heldvar(3).name=x(find(x(1,:)~=' '));
x=str2num(header(10,find(header(10,:) == ':')+1:end));
xv.heldvar(3).range=x;
x=str2num(header(11,find(header(11,:) == ':')+1:end));
xv.heldvar(3).values=x;
xv.vars={xv.heldvar(1).name;xv.heldvar(2).name;xv.heldvar(3).name};
xv.inuse=1;
crossvar %our little variable selector GUI
pause(0.1)
xv.inuse=0;
xyh = [2 3 1;1 3 2;1 2 3]; %lookup table of variable combinations
h=xv.HeldVariable; %index of variable held
% now we pick out which our X and Y variables actually are from text
a=find(header(1,:)=='/');
x=header(1,a(end-2):end);
xdata.filename=x(find(x(1,:)~=' ')); %this strips spaces
xdata.filename=[xdata.filename ':' num2str(xv.BinWidth) 'ms BW ' ' {' num2str(xdata.cellone) '/' num2str(xdata.celltwo) '}' ' Method=' num2str(george) ];
xdata.xtitle=xv.heldvar(xyh(h,1)).name;
xdata.xtitle=xdata.xtitle(find(xdata.xtitle(1,:)~=' '));
xdata.xrange=xv.heldvar(xyh(h,1)).range;
xdata.xvalues=xv.heldvar(xyh(h,1)).values;
xdata.ytitle=xv.heldvar(xyh(h,2)).name;
xdata.ytitle=xdata.ytitle(find(xdata.ytitle(1,:)~=' '));
xdata.yrange=xv.heldvar(xyh(h,2)).range;
xdata.yvalues=xv.heldvar(xyh(h,2)).values;
xdata.heldvar=xv.heldvar(xyh(h,3)).name;
xdata.heldvar=xdata.heldvar(find(xdata.heldvar(1,:)~=' '));
xdata.heldvalue=xv.heldvar(xyh(h,3)).values;
xdata.heldvalue=xdata.heldvalue(xv.HeldValue);
xdata.matrix=zeros(xdata.yrange,xdata.xrange);
xdata.xcorindex=0;
xdata.xcor.values=0;
xdata.xcor.time=0;
%--For filename indexing
firstnumber=1;
lastnumber=xdata.xrange*xdata.yrange;
end
%-Bar to show progress
h = waitbar(0,'Loading Raw Data and Computing Cross-Correlograms...');
%-Loads spike data for all variable values
for i=firstnumber:lastnumber
%--Filename to be loaded
filename = [basefilename '.' int2str(i)];
xdata.xcor(i).name=filename;
%--Load spike data for the 2 cells
switch xdata.filetype
case 'doc'
c1=lsd(filename,xdata.cellone,xv.StartTrial,xv.EndTrial);
c2=lsd(filename,xdata.celltwo,xv.StartTrial,xv.EndTrial);
otherwise
c1=lsd2(filename,xdata.cellone,xv.StartTrial,xv.EndTrial,xdata.trialtime,xdata.modtime);
c2=lsd2(filename,xdata.celltwo,xv.StartTrial,xv.EndTrial,xdata.trialtime,xdata.modtime);
end
xdata.raw{i}.cellone=c1;
xdata.raw{i}.celltwo=c2;
if ((xv.EndTrial==inf) && (i==1)) %i==1 so we only do this once!
xv.EndTrial=xdata.raw{i}.cellone.numtrials;
set(gh('EndTrial'),'String',num2str(xdata.raw{i}.cellone.numtrials));
set(gh('ShuffleNumber'),'String',nums2strs(1:(xdata.raw{i}.cellone.numtrials-1)));
set(gh('ShuffleNumber'),'value',xdata.raw{i}.cellone.numtrials-1);
end
if (get(gh('Shuffle'),'value')>1)
xv.shuffles=get(gh('ShuffleNumber'),'value');
else
xv.shuffles=0;
end
%--Get Crosscorrelation values and store them
[x,timebase,ci]=icorrx(xdata.raw{i},xv.BinWidth,xv.Window,xv.FromTime,xv.ToTime,xv.shuffles,get(gh('Shuffle'),'value'),xv.pValue);
xdata.xcor(i).values=round(x);
xdata.xcor(i).time=timebase;
if ~isempty(ci)
xdata.xcor(i).lcl=ci(1,:); %lower limits
xdata.xcor(i).ucl=ci(2,:); %upper limits
end
%--Update waitbar
waitbar(i/((lastnumber+1)-firstnumber),h);
end
close(h)
xdata.xcorindex=round(size(xdata.xcor(1).time,2)/2); %finds index into the 0 position
if strcmp(xdata.filetype,'txt') || strcmp(xdata.filetype,'smr')
datainfobox;
set(gh('TextDisplay'),'String',xdata.info);
axes(gh('XCorAxis'));
end
switch xdata.numvars
case 0
bar(xdata.xcor(i).time,xdata.xcor(i).values,1,'k');
title([xdata.runname ' - ' num2str(xdata.cellone) '&' num2str(xdata.celltwo) ' [' num2str(xv.BinWidth) 'ms BW|Trials:' num2str(xv.StartTrial) '-' num2str(xv.EndTrial) ']' ]);
case 1
xdata.ytitle='XCor Time (ms)';
if xdata.xcor(1).time(end)*2<=500
xdata.yvalues=xdata.xcor(1).time;
xdata.yrange=size(xdata.xcor(1).values,2);
xdata.matrix=zeros(xdata.yrange,xdata.xrange);
for i=1:xdata.xrange
xdata.matrix(:,i)=xdata.xcor(i).values;
end
else
index=round(500/xv.BinWidth);
indexnum=index*2+1;
xdata.yvalues=xdata.xcor(i).time(xdata.xcorindex-index:xdata.xcorindex+index);
xdata.yrange=length(xdata.yvalues);
xdata.matrix=zeros(indexnum,xdata.xrange);
for i=1:xdata.xrange
xdata.matrix(:,i)=xdata.xcor(i).values(xdata.xcorindex-index:xdata.xcorindex+index)';
end
end
xdata.xcorindex=round(size(xdata.xcor(1).time,2)/2); %finds index into the 0 position
set(gh('CCStartBin'),'String',cellstr(num2str(xdata.xcor(1).time')));
set(gh('CCEndBin'),'String',cellstr(num2str(xdata.xcor(1).time')));
% Set Up default Binning Parameters, assuming nearest to +-10msec
set(gh('CCStartBin'),'Value',xdata.xcorindex);
set(gh('CCEndBin'),'Value',xdata.xcorindex);
set(gh('CCHold1'),'String',cellstr(num2str(xdata.xvalues')));
set(gh('CCHold1'),'Value',1);
set(gh('CCHold2'),'String',cellstr(num2str(xdata.xvalues')));
set(gh('CCHold2'),'Value',length(xdata.xvalues));
xcormatrix;
fixfig;
case 2
%errordlg('Cross Cor had a problem loading 2 variables');
%error('Cross Cor had a problem loading 2 variables');
xdata.xcorindex=round(xdata.yrange/2);
% Set Up default Binning Parameters, assuming nearest to +-10msec
default=round(10/xv.BinWidth);
set(gh('CCStartBin'),'Value',xdata.xcorindex);
set(gh('CCEndBin'),'Value',xdata.xcorindex);
xdata.xcorindex=round(size(xdata.xcor(1).time,2)/2); %finds index into the 0 position
set(gh('CCStartBin'),'String',cellstr(num2str(xdata.xcor(1).time')));
set(gh('CCEndBin'),'String',cellstr(num2str(xdata.xcor(1).time')));
default=round(10/xv.BinWidth);
% Set Up default Binning Parameters, assuming nearest to +-10msec
set(gh('CCStartBin'),'Value',xdata.xcorindex);
set(gh('CCEndBin'),'Value',xdata.xcorindex);
xv.StartBin=xdata.xcorindex;%-default;
xv.EndBin=xdata.xcorindex;%+default;
for i=1:xdata.xrange*xdata.yrange %actually extract out our values into the matrix
xsum=sum(xdata.xcor(i).values(1,xv.StartBin:xv.EndBin));
xdata.matrix(i)=xsum;
end
xcormatrix;
otherwise
errordlg('Sorry, Cross Cor does not deal yet with 3 variables');
error('Sorry, Cross Cor does not deal yet with 3 variables');
end
%-------------------------------------------------------------------
case 'ReRun'
%-------------------------------------------------------------------
rerun='yes';
crosscor('Load');
%-------------------------------------------------------------------
case 'Load Matrix'
%-------------------------------------------------------------------
%clear xdata slope xv
origpath=pwd;
cd('c:\');
[file path]=uigetfile('*.mat','Load Processed Matrix');
if isempty(file), return, end;
filepath=[path '\' file];
cd(path);
load(filepath);
save 'c:\xdata' xdata
binvals=cellstr(num2str(xdata.yvalues'));
set(gh('CCStartBin'),'Value',1);
set(gh('CCEndBin'),'Value',1);
set(gh('CCStartBin'),'String',binvals);
set(gh('CCEndBin'),'String',binvals);
set(gh('CCBinWidth'),'String',num2str(xv.BinWidth));
set(gh('CCWindow'),'String',num2str(xv.Window));
set(gh('CCFromTime'),'String',num2str(xv.FromTime));
set(gh('CCToTime'),'String',num2str(xv.ToTime));
set(gh('CCStartTrial'),'String',num2str(xv.StartTrial));
set(gh('CCEndTrial'),'String',num2str(xv.EndTrial));
set(gh('CCFirstCell'),'Value',xv.firstunit);
set(gh('CCSecondCell'),'Value',xv.secondunit);
% Set Up default Binning Parameters, assuming nearest to +-10msec
default=round(10/xv.BinWidth);
set(gh('CCStartBin'),'Value',round(length(binvals)/2));
set(gh('CCEndBin'),'Value',round(length(binvals)/2));
%xv.StartBin=xdata.xcorindex;%-default;
%xv.EndBin=xdata.xcorindex;%+default;
% if xdata.ytitle=='XCor Time (ms)'
% xdata.numvars=1;
% end
xcormatrix;
%-------------------------------------------------------------------
case 'PlotMatrix'
%-------------------------------------------------------------------
xcormatrix;
%-------------------------------------------------------------------
case 'Save Model'
%-------------------------------------------------------------------
if exist('c:\temp.mat','file'); delete('c:\temp.mat'); end
crossmodelsave
b=xdata.xvalues';
a=cell(size(b));
for i=1:max(size(a))
a{i}=b(i)
end
set(gh('Angle'),'String',a);
loop=0;
while loop<1
pause(1)
end
loop=0;
model.sep=str2num(get(gh('Sep'),'String'));
model.size1=str2num(get(gh('Size1'),'String'));
model.size2=str2num(get(gh('Size2'),'String'));
String=get(gh('Type1'),'String');
Value=get(gh('Type1'),'Value');
model.type1=String{Value};
String=get(gh('Type2'),'String');
Value=get(gh('Type2'),'Value');
model.type2=String{Value};
model.optimum=get(gh('Angle'),'Value');
model.binwidth=xdata.xcor(1).time(2)-xdata.xcor(1).time(1);
model.window=abs(xdata.xcor(1).time(1))+abs(xdata.xcor(1).time(end));
close;
maxvalue=0;
for i=1:xdata.xrange
if max(xdata.xcor(i).values)>maxvalue
maxvalue=max(xdata.xcor(i).values);
end
end
if maxvalue==0
maxvalue=maxvalue+1;
end
model.maxvalue=maxvalue; %this is the maximum number of correlated events
data=xdata;
data.model=model;
[file path]=uiputfile('*.mat','Save Model Matrix')
if isempty(file), return, end;
cd(path)
x='data';
save(file,x);
%-------------------------------------------------------------------
case 'Save Matrix'
%-------------------------------------------------------------------
if ~isempty(xdata);
origpath=pwd;
cd('c:\');
[file path]=uiputfile('*.mat','Save Processed Matrix');
if isempty(file), return, end;
filepath=[path '\' file];
save(filepath,'xdata','xv');
cd(origpath);
else
errordlg('No Data has been Processed...');
end
%-------------------------------------------------------------------
case 'Save Text'
%-------------------------------------------------------------------
if ~isempty(xdata);
[file path]=uiputfile('*.wk1','Save Processed Matrix as WK1 file');
if isempty(file), return, end;
cd(path);
xmat=rot90(xdata.matrix);
xmat=flipud(xmat);
wk1write(file,xmat);
%dlmwrite('text.txt',xdata.matrix,'\t')
else
errordlg('No Data has been Processed...');
end
%-------------------------------------------------------------------
case 'Preview'
%-------------------------------------------------------------------
SpawnPlot(gca);
set(gca,'FontSize',6);
%-------------------------------------------------------------------
case 'Axis'
%-------------------------------------------------------------------
val=get(gh('Axeschk'), 'Value');
if val == 1
axis auto
set(findobj('UserData','AxesValues'),'Enable', 'off')
else
xmin=str2num(get(gh('CCXmintext'),'String'));
xmax=str2num(get(gh('CCXmaxtext'),'String'));
ymin=str2num(get(gh('CCYmintext'),'String'));
ymax=str2num(get(gh('CCYmaxtext'),'String'));
axis([xmin xmax ymin ymax]);
set(findobj('UserData','AxesValues'),'Enable', 'on');
end
%-------------------------------------------------------------------
case 'See Rasters' %look at Raster plots for both cells
%-------------------------------------------------------------------
xv.inuse=1;
if xdata.numvars<2
figure;
set(gcf,'Tag','ccrasterplotfig');
figpos(1,[900 700]);
set(gcf,'Color',[1 1 1]);
maxvalue=0;
firstnumber=get(gh('CCHold1'),'Value');
lastnumber=get(gh('CCHold2'),'Value');
range=lastnumber-firstnumber+1;
if xdata.numvars==0
range=1;
firstnumber=1;
lastnumber=1;
end
if range<=4
y=1;
x=range;
elseif range <=15
y=3;
x=ceil(range/3);
elseif range <=20
y=4;
x=ceil(range/4);
else
y=6;
x=ceil(range/6);
end
a=1;
for i=firstnumber:lastnumber
subaxis(y,x,a,'S',0.05,'P',0,'M',0.1);
plotraster(xdata.raw{i}.cellone, xdata.raw{i}.celltwo);
a=a+1;
box on
set(gca,'Layer','top');
set(gca,'TickDir','out'); %get ticks going out
xlabel([num2str(xdata.xvalues(i)) ' | Time (s)'],'FontSize',7)
end
suplabel([xdata.runname ' | Cells ' num2str(xdata.cellone) ' & ' num2str(xdata.celltwo)], 't');
end
%-------------------------------------------------------------------
case 'See PSTH' %look at PSTH plots for both cells
%-------------------------------------------------------------------
xv.inuse=1;
if xdata.numvars<2
figure;
set(gcf,'Tag','ccpsthplotfig');
figpos(1,[900 700]);
set(gcf,'Color',[1 1 1]);
maxvalue=0;
firstnumber=get(gh('CCHold1'),'Value');
lastnumber=get(gh('CCHold2'),'Value');
wrap=get(gh('CCWrapPSTH'),'Value');
range=lastnumber-firstnumber+1;
if xdata.numvars==0
range=1;
firstnumber=1;
lastnumber=1;
end
if range<=4
y=1;
x=range;
elseif range <=15
y=3;
x=ceil(range/3);
elseif range <=20
y=4;
x=ceil(range/4);
else
y=5;
x=ceil(range/5);
end
binwidth=10; %ms
a=1;
for i=firstnumber:lastnumber
if wrap==0
[var(a).t1,var(a).a1]=binit(xdata.raw{i}.cellone,binwidth*10,0,inf,xv.StartTrial,xv.EndTrial,0,'cor');
[var(a).t2,var(a).a2]=binit(xdata.raw{i}.celltwo,binwidth*10,0,inf,xv.StartTrial,xv.EndTrial,0,'cor');
var(a).a1= (var(a).a1/(binwidth*xdata.raw{i}.cellone.numtrials))*1000;
var(a).a2= (var(a).a2/(binwidth*xdata.raw{i}.cellone.numtrials))*1000;
else
[var(a).t1,var(a).a1]=binit(xdata.raw{i}.cellone,binwidth*10,0,inf,xv.StartTrial,xv.EndTrial,1,'cor');
[var(a).t2,var(a).a2]=binit(xdata.raw{i}.celltwo,binwidth*10,0,inf,xv.StartTrial,xv.EndTrial,1,'cor');
var(a).a1= (var(a).a1/(binwidth*xdata.raw{i}.cellone.numtrials*xdata.raw{i}.cellone.nummods))*1000;
var(a).a2= (var(a).a2/(binwidth*xdata.raw{i}.cellone.numtrials*xdata.raw{i}.cellone.nummods))*1000;
end
if max([var(a).a1 var(a).a2])>maxvalue
maxvalue=max([var(a).a1 var(a).a2]);
end
a=a+1;
end
a=1;
for i=firstnumber:lastnumber
subaxis(y,x,a,'M',0.1,'S',0.05);
h=plot(var(a).t1,var(a).a1,'k',var(a).t2,var(a).a2,'r');
set(h,'LineWidth',1.5);
xlabel(num2str(xdata.xvalues(i)),'FontSize',7)
axis tight;
set(gca,'FontSize',4);
axis([-inf inf 0 maxvalue+(maxvalue/10)]);
a=a+1;
set(gca,'Layer','top');
set(gca,'TickDir','out'); %get ticks going out
end
else
figure
maxvalue=0;
for i=1:xdata.xrange*xdata.yrange
subplot(xdata.yrange,xdata.xrange,i);
[t1,a1]=binit(xdata.raw{i}.cellone,250,0,inf,xv.StartTrial,xv.EndTrial,0);
[t2,a2]=binit(xdata.raw{i}.celltwo,250,0,inf,xv.StartTrial,xv.EndTrial,0);
if max([a1*100 a2*100])>maxvalue
maxvalue=max([a1*100 a2*100]);
end
plot(t1,a1*100,'b',t2,a2*100,'r');
%axis tight
set(gca,'FontSize',4);
%ylabel(xdata.xcor(i).name,'FontSize',5)
end
for i=1:xdata.xrange*xdata.yrange
subplot(xdata.yrange,xdata.xrange,i);
axis tight;
yaxis(0,maxvalue);
set(gca,'Layer','top');
set(gca,'TickDir','out'); %get ticks going out
end
set(gcf,'Color',[1 1 1]);
end
xv.inuse=0;
suplabel([xdata.runname ' Cells:' num2str(xdata.cellone) '&' num2str(xdata.celltwo)] ,'t');
%-------------------------------------------------------------------
case 'See XCor' %see Xcorrelograms
%-------------------------------------------------------------------
if xdata.numvars>=1
maxvalue=0;
x=ceil(xdata.xrange/3);
for i=1:xdata.xrange
if max(xdata.xcor(i).values)>maxvalue
maxvalue=max(xdata.xcor(i).values);
end
end
if maxvalue==0
maxvalue=maxvalue+1;
end
figure;
set(gcf,'Tag','cccorrplotfig');
figpos(1,[900 700]);
set(gcf,'Color',[1 1 1]);
firstnumber=get(gh('CCHold1'),'Value');
lastnumber=get(gh('CCHold2'),'Value');
range=lastnumber-firstnumber+1;
if xdata.numvars==0
range=1;
firstnumber=1;
lastnumber=1;
end
if range<=4
y=1;
x=range;
elseif range <=15
y=3;
x=ceil(range/3);
elseif range <=20
y=4;
x=ceil(range/4);
else
y=5;
x=ceil(range/5);
end
a=1;
for i=firstnumber:lastnumber
subaxis(y,x,a,'M',0.05,'S',0.05);
set(gca,'nextplot','add')
bar(xdata.xcor(i).time,xdata.xcor(i).values,1,'k')
if isfield(xdata.xcor(1),'lcl')
plot(xdata.xcor(i).time,xdata.xcor(i).lcl,'r-');
plot(xdata.xcor(i).time,xdata.xcor(i).ucl,'r-');
end
axis tight
set(gca,'FontSize',4)
xlabel(num2str(xdata.xvalues(i)),'FontSize',6)
axis([-inf inf 0 maxvalue]);
set(gca,'Layer','top');
set(gca,'TickDir','out'); %get ticks going out
a=a+1;
end
else
maxvalue=0;
for i=1:xdata.xrange*xdata.yrange
if max(xdata.xcor(i).values)>maxvalue
maxvalue=max(xdata.xcor(i).values);
end
end
if maxvalue==0
maxvalue=maxvalue+1;
end
figure
set(gcf,'Color',[1 1 1]);
for i=1:xdata.xrange*xdata.yrange
subplot(xdata.xrange,xdata.yrange,i)
bar(xdata.xcor(i).time,xdata.xcor(i).values,1,'k')
axis tight
set(gca,'FontSize',4);
set(gca,'Layer','top');
set(gca,'TickDir','out'); %get ticks going out
%ylabel(xdata.xcor(i).name,'FontSize',5)
axis([-inf inf 0 maxvalue]);
end
end
%-------------------------------------------------------------------
case 'See Tuning'
%-------------------------------------------------------------------
if xdata.numvars==1
datatype='Tune';
cla;
x=xdata.xvalues;
corrline=[];
s=get(gh('CCStartBin'),'Value');
f=get(gh('CCEndBin'),'Value');
stext=get(gh('CCStartBin'),'String');
ftext=get(gh('CCEndBin'),'String');
stext=stext{s};
ftext=ftext{f};
for i=1:xdata.xrange
xsum=sum(xdata.matrix(s:f,i));
corrline(i)=xsum;
e=xdata.matrix(s:f,i);
err(i)=std(e);
end
[e,a]=max(corrline);
angle=x(a);
set(gh('CCGauss1'),'String',num2str(max(corrline)));
set(gh('CCGauss2'),'String',num2str(5));
set(gh('CCGauss3'),'String',num2str(min(corrline)));
set(gh('CCGauss4'),'String',num2str(angle));
if max(err)==0
if size(corrline,1)>size(corrline,2)
corrline=corrline';
end
%corrline=(corrline/max(corrline))*100;
xdata.corrline=corrline;
plot(x,corrline,'k.-','MarkerSize',15);
t=[xdata.filename ' (Zero Bin)'];
title(t)
%pause(0.7);
%[file,path]=uiputfile('*.txt','Save Tuning Curve as:');
%if ~file
% h=helpdlg('No File Specified');
% pause(0.6);
% close(h);
%else
% cd(path);
% x=xdata.xvalues;
% save(file, 'x','corrline', '-ascii', '-tabs');
%end
else
err=err';
err=sqrt((err.^2/(f-s)));
xval=xdata.xvalues';
corrline=corrline';
%err=(err/max(corrline))*100;
%corrline=(corrline/max(corrline))*100;
areabar(xval,corrline,err,[.7 .7 .7],'k.-','MarkerSize',15);
xdata.corrline=corrline;
xdata.errorline=err;
t=[xdata.filename '(Bins: ' stext ' :' ftext ')'];
title(t,'FontSize',8)
%pause(0.7);
%[file,path]=uiputfile('*.txt','Save Tuning Curve as:');
%if ~file
% h=helpdlg('No File Specified');
% pause(0.7);
% close(h);
%else
% cd(path);
% x=xdata.xvalues;
% corrline=corrline';
% error=error';
% save(file, 'x','corrline', 'error', '-ascii', '-tabs');
%end
end
axis tight;
xlabel('Orientation (deg)');
ylabel('Correlated Events');
val=get(gh('Axeschk'), 'Value');
if val == 1
axis([-inf inf -inf inf]);
else
xmin=str2num(get(gh('CCXmintext'),'String'));
xmax=str2num(get(gh('CCXmaxtext'),'String'));
ymin=str2num(get(gh('CCYmintext'),'String'));
ymax=str2num(get(gh('CCYmaxtext'),'String'));
axis([xmin xmax ymin ymax]);
end
else
errordlg('Sorry, this function is for 1 variable data only')
end
%-------------------------------------------------------------------
case 'Fit Gaussian'
%-------------------------------------------------------------------
if datatype=='Tune';
cline=xdata.corrline;
x=xdata.xvalues;
s=get(gh('CCStartBin'),'Value');
f=get(gh('CCEndBin'),'Value');
stext=get(gh('CCStartBin'),'String');
ftext=get(gh('CCEndBin'),'String');
stext=stext{s};
ftext=ftext{f};
val=get(gh('Axeschk'), 'Value');
if val == 1
axis([-inf inf -inf inf]);
else
xmin=str2num(get(gh('CCXmintext'),'String'));
xmax=str2num(get(gh('CCXmaxtext'),'String'));
ymin=str2num(get(gh('CCYmintext'),'String'));
ymax=str2num(get(gh('CCYmaxtext'),'String'));
axis([xmin xmax ymin ymax]);
end
axval=axis;
a=find(x>=axval(1) & x<=axval(2));
x=x(a);
y=cline(a);
%this allows one to select interpolated or raw data to fit
%comment it out to use raw data...
xx=linspace(min(x),max(x),length(x)*20);
yy=interp1(x,y,xx,'linear');
x=xx;
y=yy;
%---------------------------------------------------------
lb=[10 1 0 -360];
ub=[1000 50 200 360];
g(1)=str2num(get(gh('CCGauss1'),'String'));
g(2)=str2num(get(gh('CCGauss2'),'String'));
if get(gh('CCGauss3Lock'),'Value')==1
g(3)=0;
else
g(3)=str2num(get(gh('CCGauss3'),'String'));
end
g(4)=str2num(get(gh('CCGauss4'),'String'));
options = optimset('Display','iter');
[g,f,exit,output]=fmincon(@fitgaussian,g,[],[],[],[],lb,ub,[],options,x,y);
gline=fitgaussian2(g,x);
if max(gline)-min(gline)<2.5
errordlg('Gaussian didn''t fit data, please try other parameters');
error('Gaussian didn''t fit data, please try other parameters');
elseif exit<=0
errordlg('Gaussian didn''t converge, please try other parameters');
error('Gaussian didn''t converge, please try other parameters');
end
hold on
plot(x,gline,'r');
axval=axis;
if axval==inf | axval==-inf
axval(1)=min(x);
axval(2)=max(x);
axval(3)=min(y);
axval(4)=max(y);
end
[n,j]=max(gline);
[nn,jj]=min(gline);
half=((n-nn)/2)+nn;
line([axval(1) axval(2)],[half half],'Color', [1 0 0],'LineStyle',':');
line([x(j) x(j)],[axval(3) axval(4)],'Color', [1 0 0],'LineStyle',':');
[o,p]=ginput(2)
[m,i]=max(gline);
n=x(j);
ap=n-o(1);
bp=o(2)-n;
hwp=(ap+bp)/2;
[o,p]=ginput(1);
t=['Gaussian HwHH = ' num2str(hwp) '|' num2str(g)];
text(o,p,t);
hold off
end
%-------------------------------------------------------------------
case 'Half Width'
%-------------------------------------------------------------------
if datatype=='Tune';
cline=[];