-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathplotcurves.m
1352 lines (1217 loc) · 38.3 KB
/
plotcurves.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 [sel, varc, spot, sets] = plotcurves(hfile, opts)
% plotcurves - plot different curves and select those of interest
%
% FORMAT: [sel, varc, spot, sets] = plotcurves(obj [, opts]]);
%
% Input fields:
%
% obj xff object with plotable data or SxC double data
% opts optional settings
% .cuediff difference between cue and onset (only useful if
% fixed interval!; default: -2)
% .curves Cx2 cell array with names and a 1x3 double array
% containing [channelnumber, onset, offset]
% - for curves in a set, the mean/std. error is computed
% - onset and offset are given in seconds
% .dchannel data channel (for onset detection, default: 1)
% .dfilt detection filter length (in seconds, default: 0.5)
% .dminlat minimum detection latency (after one point, def: 0.5)
% .freq data sampling frequency (if not in object, def: 100)
% .ochannel onset channel number (will add curves, default: [])
% .odchannel original data channel (allows to filter effect)
% .onsets Ox1 onset vector in seconds
% .owin 1x2 onset window in seconds (default: [-2, 18])
% .sets Sx2 cell array with names and lists of curve indices
% .spot Sx1 cell array with Cx1 X or Cx2 x/y time-points
% .spotnames Sx1 cell array with strings
% .spottype Sx1 cell array with either of
% 'cue', {'free'}, 'max', 'min', 'minmax', 'onset'
% .var 1xV struct with fields (up to 6 variables)
% .calc either of 'dx', {'dy'}, 'mean', 'std', 'var', 'x', 'y'
% .name variable name
% .spot 1x1 or 1x2 index into S
% .trans apply additional transformation to each value, one of
% {'none'}, 'log', 'log+1', 'sqrt'
%
% Output fields:
%
% sel selection (Cx1 boolean array)
% varc computed variables
% spot updated spots
% sets updates sets (new indices)
%
% Note: where appropriate, the options are taken from obj.RunTimeVars
% if not specified in the call!
% Version: v0.9d
% Build: 14061709
% Date: Jun-17 2014, 9:50 AM EST
% Author: Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://neuroelf.net/
% Copyright (c) 2010, 2011, 2014, Jochen Weber
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in the
% documentation and/or other materials provided with the distribution.
% * Neither the name of Columbia University nor the
% names of its contributors may be used to endorse or promote products
% derived from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
% variable for UI stuff
global ne_ui;
% allow double data to be used
delobj = false;
if nargin > 0 && ...
isa(hfile, 'double')
delobj = true;
ntt = xff('new:ntt');
ntt.Data = hfile;
hfile = ntt;
end
% argument check
if nargin < 1 || ...
numel(hfile) ~= 1 || ...
~isxff(hfile, {'acq', 'ntt'})
error( ...
'neuroelf:InvalidCall', ...
'Invalid call to plotcurves.' ...
);
end
ft = lower(hfile.Filetype);
switch (ft)
case {'acq'}
nc = hfile.NrOfChannels;
freq = 1000 / hfile.MillisecsPerSample;
case {'ntt'}
nc = size(hfile.Data, 2);
freq = 100;
end
if nargin < 2 || ...
numel(opts) ~= 1 || ...
~isstruct(opts)
opts = struct;
end
if isfield(opts, 'freq') && ...
isa(opts.freq, 'double') && ...
numel(opts.freq) == 1 && ...
~isinf(opts.freq) && ...
~isnan(opts.freq) && ...
opts.freq >= 0.01
freq = opts.freq;
end
if ~isfield(opts, 'cuediff') || ...
~isa(opts.cuediff, 'double') || ...
numel(opts.cuediff) ~= 1 || ...
isinf(opts.cuediff) || ...
isnan(opts.cuediff)
opts.cuediff = -2;
end
if ~isfield(opts, 'curves') || ...
~iscell(opts.curves) || ...
size(opts.curves, 2) ~= 2 || ...
ndims(opts.curves) > 2
opts.curves = cell(0, 2);
end
for cc = 1:size(opts.curves, 1)
if ~ischar(opts.curves{cc, 1}) || ...
isempty(opts.curves{cc, 1}) || ...
~isa(opts.curves{cc, 2}, 'double') || ...
size(opts.curves{cc, 2}, 2) ~= 3 || ...
any(isinf(opts.curves{cc, 2}(:)) | isnan(opts.curves{cc, 2}(:))) || ...
any(any(opts.curves{cc, 2} < 1, 2) | opts.curves{cc, 2}(:, 1) > nc)
error( ...
'neuroelf:BadArgument', ...
'Invalid curve selection for curve %d.', ...
cc ...
);
end
end
if ~isfield(opts, 'dchannel') || ...
~isa(opts.dchannel, 'double') || ...
numel(opts.dchannel) ~= 1 || ...
isinf(opts.dchannel) || ...
isnan(opts.dchannel) || ...
opts.dchannel < 1 || ...
opts.dchannel ~= fix(opts.dchannel) || ...
opts.dchannel > nc
opts.dchannel = 1;
end
if ~isfield(opts, 'dfilt') || ...
~isa(opts.dfilt, 'double') || ...
numel(opts.dfilt) ~= 1 || ...
isinf(opts.dfilt) || ...
isnan(opts.dfilt) || ...
opts.dfilt < 0 || ...
opts.dfilt > 30
opts.dfilt = 0.5;
end
if opts.dfilt == 0;
dfiltk = [];
else
dfiltk = smoothkern(freq * opts.dfilt, 1.42e-5 / (freq * opts.dfilt));
dfiltk = flexinterpn_method(dfiltk, [Inf; 1; 1 / 4096; numel(dfiltk)], 'cubic');
end
if ~isfield(opts, 'dminlat') || ...
~isa(opts.dminlat, 'double') || ...
numel(opts.dminlat) ~= 1 || ...
isinf(opts.dminlat) || ...
isnan(opts.dminlat) || ...
opts.dminlat < 0
opts.dminlat = 0.5;
end
if ~isfield(opts, 'owin') || ...
~isa(opts.owin, 'double') || ...
isempty(opts.owin) || ...
numel(opts.owin) > 2 || ...
any(isinf(opts.owin) | isnan(opts.owin)) || ...
(opts.owin(end) - opts.owin(1)) < 0 || ...
(opts.owin(end) - opts.owin(1)) > 60
opts.owin = [-2, 18];
elseif numel(opts.owin) == 1
opts.owin = opts.owin + [0, 20];
end
if ~isfield(opts, 'ochannel') || ...
~isa(opts.ochannel, 'double') || ...
numel(opts.ochannel) ~= 1 || ...
isinf(opts.ochannel) || ...
isnan(opts.ochannel) || ...
opts.ochannel < 1 || ...
opts.ochannel ~= fix(opts.ochannel) || ...
opts.ochannel > nc
opts.ochannel = [];
onsets = [];
else
och = hfile.ChannelData(opts.ochannel);
mmoch = minmaxmean(och);
mmoch = 0.5 * (mmoch(1) + mmoch(2));
och = (och >= mmoch);
onsets = (1 / freq) .* find(~och(1:end-1) & och(2:end));
end
if ~isfield(opts, 'odchannel') || ...
~isa(opts.odchannel, 'double') || ...
numel(opts.odchannel) ~= 1 || ...
isinf(opts.odchannel) || ...
isnan(opts.odchannel) || ...
opts.odchannel < 1 || ...
opts.odchannel ~= fix(opts.odchannel) || ...
opts.odchannel > nc
opts.odchannel = [];
end
if isfield(opts, 'onsets') && ...
isa(opts.onsets, 'double') && ...
numel(opts.onsets) == max(size(opts.onsets)) && ...
~any(isinf(opts.onsets) | isnan(opts.onsets) | opts.onsets < 0)
onsets = opts.onsets(:);
end
if ~isempty(onsets)
ncr = size(opts.curves, 1);
opts.curves = [opts.curves; cell(numel(onsets), 2)];
for cc = 1:numel(onsets)
opts.curves{ncr + cc, 1} = ...
sprintf('Onset %d, t=%.3f', cc, onsets(cc));
opts.curves{ncr + cc, 2} = [opts.dchannel, onsets(cc) + opts.owin];
end
end
if ~isfield(opts, 'sets') || ...
~iscell(opts.sets) || ...
isempty(opts.sets) || ...
size(opts.sets, 2) ~= 2 || ...
ndims(opts.sets) > 2
if nc == (size(opts.curves, 1) + numel(onsets)) || ...
~isfield(opts, 'sets') || ...
~iscell(opts.sets) || ...
size(opts.sets, 2) ~= 2 || ...
ndims(opts.sets) > 2
opts.sets = {'Overall mean', 1:nc};
if ~isempty(onsets)
opts.sets(2, :) = {'Onsets mean', nc+1:nc+numel(onsets)};
end
end
end
if ~isfield(opts, 'spot') || ...
~iscell(opts.spot) || ...
all(cellfun('isempty', opts.spot))
if ~isfield(hfile.RunTimeVars, 'plotcurves') || ...
~isstruct(hfile.RunTimeVars.plotcurves) || ...
~isfield(hfile.RunTimeVars.plotcurves, 'spot')
if ~isfield(opts, 'spot') || ...
~iscell(opts.spot)
opts.spot = {};
end
else
opts.spot = hfile.RunTimeVars.plotcurves.spot;
end
else
opts.spot = opts.spot(:);
end
if isempty(opts.spot)
opts.spot = {cat(1, opts.curves{:, 2})};
opts.spot{1} = opts.spot{1}(:, 2);
end
if ~isfield(opts, 'spotnames') || ...
~iscell(opts.spotnames) || ...
numel(opts.spotnames) ~= numel(opts.spot)
opts.spotnames = cell(1, numel(opts.spot));
else
opts.spotnames = opts.spotnames(:);
end
if ~isfield(opts, 'spottype') || ...
~iscell(opts.spottype) || ...
numel(opts.spottype) ~= numel(opts.spot)
opts.spottype = cell(1, numel(opts.spot));
else
opts.spottype = opts.spottype(:);
end
for sc = numel(opts.spot):-1:1
if ~isa(opts.spot{sc}, 'double') || ...
ndims(opts.spot{sc}) ~= 2 || ...
(~isempty(opts.spot{sc}) && ...
size(opts.spot{sc}, 1) ~= size(opts.curves, 1)) || ...
~any(size(opts.spot{sc}, 2) == [1, 2]) || ...
any(isinf(opts.spot{sc}(:)) | isnan(opts.spot{sc}(:))) || ...
any(opts.spot{sc}(:, 1) < 0)
opts.spot(sc) = [];
opts.spotnames(sc) = [];
opts.spottype(sc) = [];
continue;
end
if ~ischar(opts.spotnames{sc}) || ...
isempty(opts.spotnames{sc})
opts.spotnames{sc} = sprintf('Spot %d', sc);
else
opts.spotnames{sc} = opts.spotnames{sc}(:)';
end
if ~ischar(opts.spottype{sc}) || ...
isempty(opts.spottype{sc}) || ...
~any(strcmpi(opts.spottype{sc}(:)', ...
{'c', 'cue', 'f', 'free', 'max', 'min', 'minmax', 'n', 'none', 'o', 'onset'}))
opts.spottype{sc} = 'free';
else
opts.spottype{sc} = lower(opts.spottype{sc}(:)');
end
end
findspot = false;
for sc = 1:numel(opts.spot)
if isempty(opts.spot{sc})
findspot = true;
opts.spot{sc} = zeros(size(opts.curves, 1), 1);
for ssc = 1:size(opts.curves, 1)
spcrv = opts.curves{ssc, 2};
if opts.spottype{sc}(1) == 'm'
spotc = diff(hfile.SampleData( ...
spcrv(1), spcrv(2), spcrv(3), ...
ceil(freq * (spcrv(3) - spcrv(2))), freq));
if ~isempty(dfiltk)
spotc = flexinterpn(spotc, ...
[Inf; 1; 1; numel(spotc)], dfiltk, 4096, 0);
end
spotc = sign(spotc);
spotc(find(spotc(1:end-1) ~= spotc(2:end))) = 0;
if sc == 1
spots = ceil(1 - freq * opts.owin(1));
else
spots = min(numel(spotc), ...
ceil(2 + freq * (opts.dminlat + ...
opts.spot{sc-1}(ssc, 1) - spcrv(2))));
end
end
switch (opts.spottype{sc})
case {'cue'}
spott = ceil(1 - freq * (opts.owin(1) + opts.cuediff));
case {'f', 'free', 'n', 'none', 'o', 'onset'}
spott = ceil(1 - freq * opts.owin(1));
case {'max'}
if spotc(spots <= 0)
spots = findfirst(spotc > 0, spots);
if isempty(spots)
spots = numel(spotc);
end
end
spott = findfirst(spotc < 0, spots);
case {'min'}
if spotc(spots >= 0)
spots = findfirst(spotc < 0, spots);
if isempty(spots)
spots = numel(spotc);
end
end
spott = findfirst(spotc > 0, spots);
case {'minmax'}
spott = findfirst(sign(spotc) == -sign(spotc(1)), spots);
end
if isempty(spott)
spott = numel(spotc);
end
opts.spot{sc}(ssc, 1) = spcrv(2) + (spott - 1) / freq;
end
end
end
if ~isfield(opts, 'var') || ...
~isstruct(opts.var) || ...
isempty(opts.var) || ...
~isfield(opts.var, 'calc') || ...
~isfield(opts.var, 'spot') || ...
~isfield(opts.var, 'trans')
opts.var = struct('calc', 'y', 'spot', 1, 'trans', 'none');
end
opts.var = opts.var(:);
for vc = numel(opts.var):-1:1
if ~isa(opts.var(vc).spot, 'double') || ...
~any(numel(opts.var(vc).spot) == [1, 2]) || ...
any(isinf(opts.var(vc).spot) | isnan(opts.var(vc).spot) | ...
opts.var(vc).spot < 1 | opts.var(vc).spot > numel(opts.spot) | ...
opts.var(vc).spot ~= fix(opts.var(vc).spot)) || ...
numel(unique(opts.var(vc).spot)) ~= numel(opts.var(vc).spot)
opts.var(vc) = [];
continue;
end
if ~ischar(opts.var(vc).calc) || ...
isempty(opts.var(vc).calc) || ...
~any(strcmpi(opts.var(vc).calc(:)', ...
{'dx', 'dy', 'm', 'mean', 's', 'std', 'v', 'var', 'x', 'y'}))
if numel(opts.var(vc).spot) > 1
opts.var(vc).calc = 'dy';
else
opts.var(vc).calc = 'y';
end
else
opts.var(vc).calc = lower(opts.var(vc).calc(:)');
end
if any(strcmp(opts.var(vc).calc, ...
{'dx', 'dy', 'm', 'mean', 's', 'std', 'v', 'var'})) && ...
numel(opts.var(vc).spot) < 2
error( ...
'neuroelf:BadArgument', ...
'The %d calculation requires 2 spots.', ...
opts.var(vc).calc ...
);
end
if ~ischar(opts.var(vc).trans) || ...
isempty(opts.var(vc).trans) || ...
~any(strcmpi(opts.var(vc).trans(:)', ...
{'n', 'none', 'l', 'log', 'log+1', 'r', 's', 'sqrt'}))
opts.var(vc).trans = 'none';
else
opts.var(vc).trans = lower(opts.var(vc).trans(:)');
end
if ~isfield(opts.var(vc), 'name') || ...
~ischar(opts.var(vc).name) || ...
isempty(opts.var(vc).name)
opts.var(vc).name = sprintf('Var %d', vc);
end
end
if numel(opts.var) > 6
opts.var = opts.var(1:6);
end
if isempty(opts.curves)
opts.curves = cell(nc, 2);
for cc = 1:nc
opts.curves{cc, 1} = sprintf('channel %d', cc);
opts.curves{cc, 2} = [cc, 0, numel(hfile.ChannelData(cc)) / freq];
end
end
% fill in initial spot y values
for sc = 1:numel(opts.spot)
if size(opts.spot{sc}, 2) == 1
opts.spot{sc}(:, 2) = 0;
for cc = 1:size(opts.curves, 1)
opts.spot{sc}(cc, 2) = hfile.SampleData(opts.curves{cc, 2}(1), ...
opts.spot{sc}(cc, 1), opts.spot{sc}(cc, 1), 1, freq);
end
end
end
% prepare
ne_ui.plotcurves = struct( ...
'ax', -1, ...
'axlx', [], ...
'axly', [], ...
'axpos', [-1, -1], ...
'btdwn', false, ...
'cpbtd', [-1, -1], ...
'cpos', [-1, -1], ...
'freq', freq, ...
'hFig', [], ...
'hFigM', -1, ...
'hTag', struct, ...
'hevnt', false, ...
'mctrl', false, ...
'mshft', false, ...
'obj', hfile, ...
'opts', opts, ...
'ovch', 0, ...
'sel', [], ...
'spot', [], ...
'spota', [], ...
'spotx', [], ...
'varc', zeros(size(opts.curves, 1), numel(opts.var)), ...
'zoomp', []);
% pre-compute values
pc_compute;
% load figure
try
hFig = neuroelf_file('f', 'plotcurves');
hTag = hFig.TagStruct;
catch ne_eo;
error( ...
'neuroelf:xfigureError', ...
'Error creating UI for colorpicker: %s.', ...
ne_eo.message ...
);
end
% make settings
if isfield(hfile.RunTimeVars, 'plotcurves') && ...
isstruct(hfile.RunTimeVars.plotcurves) && ...
isfield(hfile.RunTimeVars.plotcurves, 'sel') && ...
numel(hfile.RunTimeVars.plotcurves.sel) == size(opts.curves, 1)
sel = hfile.RunTimeVars.plotcurves.sel;
else
if findspot && ...
~isempty(opts.var) && ...
~isempty(opts.var(1).name) && ...
lower(opts.var(1).name(1)) == 'l'
ovarc = ne_ui.plotcurves.varc;
[mlat, wlat] = robustmean(ovarc(:, 1));
mvarc = mean(ovarc(wlat >= 0.5, :));
svarc = std(ovarc(wlat >= 0.5, :));
lvarc = repmat(mvarc - 1.5 * svarc, size(ovarc, 1), 1);
uvarc = repmat(mvarc + 1.5 * svarc, size(ovarc, 1), 1);
sel = (wlat >= 0.5) & ...
~(sum(ovarc < lvarc | ovarc > uvarc, 2) >= (1 + 0.25 * size(ovarc, 2)));
else
sel = true(size(opts.curves, 1), 1);
end
end
cnames = [opts.sets(:, 1); opts.curves(:, 1)];
for cnc = size(opts.sets, 1)+1:numel(cnames)
if sel(cnc - size(opts.sets, 1))
cnames{cnc} = sprintf('(+) %s', cnames{cnc});
else
cnames{cnc} = sprintf('(-) %s', cnames{cnc});
end
end
hTag.CB_plotcurves_focurve.Value = 1;
hTag.LB_plotcurves_curves.String = cnames;
hTag.LB_plotcurves_curves.Value = 1 + size(opts.sets, 1);
set(hTag.AX_plotcurves_zoombar.MLHandle, ...
'Color', [.6, .6, .6], ...
'XColor', [.6, .6, .6], ...
'YColor', [.6, .6, .6], ...
'XLim', [0, 1], ...
'YLim', [0, 1], ...
'XTick', [], ...
'YTick', [], ...
'ZTick', []);
for vc = 1:numel(opts.var)
hFig.SetGroupVisible(sprintf('GVar%d', vc));
hTag.(sprintf('TX_plotcurves_var%d', vc)).String = opts.var(vc).name;
end
chax = hTag.AX_plotcurves_plot.MLHandle;
set(chax, 'Units', 'pixels');
if isempty(opts.odchannel)
hTag.Plot = plot(chax, [0; 1], [0; 1]);
else
hTag.Plot = plot(chax, [0; 1], [0, 0; 1, 1]);
end
set(hTag.Plot(1), 'LineWidth', 2);
hTag.CursorX = line([0.5; 0.5], [0.001; 0.999], 'Color', [0, 0, 0], 'Parent', chax);
hTag.CursorY = line([0; 0.999], [0.5; 0.5], 'Color', [0, 0, 0], 'Parent', chax);
axpos = get(chax, 'Position');
hold(hTag.AX_plotcurves_plot.MLHandle, 'on');
% put in global structure
ne_ui.plotcurves.ax = chax;
ne_ui.plotcurves.axpos = axpos;
ne_ui.plotcurves.cpos = round(0.5 * hTag.AX_plotcurves_plot.Position(3:4));
ne_ui.plotcurves.hFig = hFig;
ne_ui.plotcurves.hFigM = hFig.MLHandle;
ne_ui.plotcurves.hTag = hTag;
ne_ui.plotcurves.sel = sel;
% set callbacks
hTag.DD_plotcurves_filter.Callback = @pc_setfilter;
hTag.LB_plotcurves_curves.Callback = @pc_showcurve;
hTag.CB_plotcurves_usecurve.Callback = @pc_toggleusecurve;
hTag.ED_plotcurves_var1.Callback = {@pc_updatevar, 1};
hTag.ED_plotcurves_var2.Callback = {@pc_updatevar, 2};
hTag.ED_plotcurves_var3.Callback = {@pc_updatevar, 3};
hTag.ED_plotcurves_var4.Callback = {@pc_updatevar, 4};
hTag.ED_plotcurves_var5.Callback = {@pc_updatevar, 5};
hTag.ED_plotcurves_var6.Callback = {@pc_updatevar, 6};
hFig.KeyPressFcn = @pc_keypress;
hFig.KeyReleaseFcn = @pc_keyrelease;
hFig.WindowButtonDownFcn = @pc_btdown;
hFig.WindowButtonMotionFcn = @pc_btmove;
hFig.WindowButtonUpFcn = @pc_btup;
% show current selection
pc_showcursor;
pc_showcurve;
% wait for dialog to finish
hFig.HandleVisibility = 'callback';
hFig.Visible = 'on';
uiwait(hFig.MLHandle);
% get selection
sel = ne_ui.plotcurves.sel;
% apply transformation
varc = ne_ui.plotcurves.varc;
for vc = 1:numel(opts.var)
switch (opts.var(vc).trans)
case {'l', 'ln', 'log'}
ne_ui.plotcurves.varc(:, vc) = log(varc(:, vc));
case {'log+1'}
ne_ui.plotcurves.varc(:, vc) = log(1 + varc(:, vc));
case {'log10'}
ne_ui.plotcurves.varc(:, vc) = log10(varc(:, vc));
case {'log2'}
ne_ui.plotcurves.varc(:, vc) = log2(varc(:, vc));
case {'r', 'root', 'sqrt'}
ne_ui.plotcurves.varc(:, vc) = sqrt(varc(:, vc));
end
end
% delete object if necessary
if delobj
hfile.ClearObject;
% otherwise...
else
% add output to RunTimeVars of object
hfile.RunTimeVars.plotcurves = struct( ...
'sel', sel, ...
'sets', {ne_ui.plotcurves.opts.sets}, ...
'spot', {ne_ui.plotcurves.opts.spot}, ...
'spotnames', {opts.spotnames}, ...
'spottype', {opts.spottype}, ...
'var', {opts.var}, ...
'varc', ne_ui.plotcurves.varc);
% try to save
try
if ~isempty(hfile.FilenameOnDisk)
hfile.SaveRunTimeVars;
end
catch ne_eo;
neuroelf_lasterr(ne_eo);
warning( ...
'neuroelf:SaveMATFailed', ...
'Couldn''t save RunTimeVars to disk; please store manually.' ...
);
end
end
% output arguments
if nargout > 2
varc = ne_ui.plotcurves.varc;
if nargout > 3
spot = ne_ui.plotcurves.spot;
if nargout > 4
sets = ne_ui.plotcurves.sets;
end
end
end
% remove field
ne_ui = rmfield(ne_ui, 'plotcurves');
% functions
% compute variables
function pc_compute(varargin)
global ne_ui;
c = ne_ui.plotcurves;
% curve selection
if nargin > 0 && ...
isa(varargin{1}, 'double')
cis = varargin{1}(:)';
else
cis = 1:size(c.opts.curves, 1);
end
% get conf
curve = c.opts.curves(:, 2);
obj = c.obj;
spot = c.opts.spot;
var = c.opts.var;
% create new varc
varc = zeros(numel(cis), numel(var));
% iterate over curves
for cc = 1:numel(cis)
% curve index
ci = cis(cc);
% iterate over vars
for vc = 1:numel(var)
% get snippet of data that we need
if numel(var(vc).spot) > 1 && ...
any(var(vc).calc(1) == 'msv')
snip = obj.ChannelData(curve{ci}(1), floor(x1):ceil(x2));
end
% depending on calculation type
switch (var(vc).calc)
case {'dx'}
val = spot{var(vc).spot(2)}(ci, 1) - spot{var(vc).spot(1)}(ci, 1);
case {'dy'}
val = spot{var(vc).spot(2)}(ci, 2) - spot{var(vc).spot(1)}(ci, 2);
case {'m', 'mean'}
val = sum(snip) / numel(snip);
case {'s', 'std'}
if numel(snip) > 1
val = std(snip);
else
val = 0;
end
case {'v', 'var'}
if numel(snip) > 1
val = varc(snip);
else
val = 0;
end
case {'x'}
val = spot{var(vc).spot(1)}(ci, 1);
case {'y'}
val = spot{var(vc).spot(1)}(ci, 2);
end
% store in matrix
varc(cc, vc) = val;
end
end
% store in global matrix
ne_ui.plotcurves.varc(cis, :) = varc;
% update var from UI
function pc_updatevar(varargin)
global ne_ui;
c = ne_ui.plotcurves;
% argument check
if nargin < 3 || ...
~isa(varargin{3}, 'double') || ...
numel(varargin{3}) ~= 1 || ...
~any(varargin{3} == 1:6)
return;
end
vars = varargin{3};
% get current selection
csel = c.hTag.LB_plotcurves_curves.Value;
if isempty(csel) || ...
csel <= size(c.opts.sets, 1)
return;
end
csel = csel - size(c.opts.sets, 1);
% get vars
varc = c.varc;
% get current value
curval = varc(csel, vars);
% get string
uic = sprintf('ED_plotcurves_var%d', vars);
newval = c.hTag.(uic).String;
% check
try
newval = str2double(newval);
if numel(newval) ~= 1 || ...
isinf(newval) || ...
isnan(newval)
newval = curval;
end
ne_ui.plotcurves.varc(csel, vars) = newval;
catch ne_eo;
neuroelf_lasterr(ne_eo);
newval = curval;
end
% set new string
c.hTag.(uic).String = sprintf('%g', newval);
% hit mouse
function pc_btdown(varargin)
global ne_ui;
c = ne_ui.plotcurves;
% check if within axes
f = c.hFig;
% get current point and compare to axes
cp = f.CurrentPoint - c.axpos(1:2);
if ~all(cp >= 0) || ...
~all(cp <= c.axpos(3:4))
return;
end
% set button down true
ne_ui.plotcurves.btdwn = true;
ne_ui.plotcurves.cpbtd = cp;
% release mouse
function pc_btup(varargin)
global ne_ui;
% set button down false
ne_ui.plotcurves.btdwn = false;
% now, get config
c = ne_ui.plotcurves;
% clear potential zoom patch
if ~isempty(c.zoomp)
delete(c.zoomp);
ne_ui.plotcurves.zoomp = [];
pc_handlezoom;
end
% move cursor
function pc_btmove(varargin)
global ne_ui;
c = ne_ui.plotcurves;
% check figure
if nargin < 1 || ...
varargin{1} ~= c.hFigM
return;
end
% more settings
f = c.hFig;
% get current point and compare to axes
cp = f.CurrentPoint - c.axpos(1:2);
if (~all(cp >= 0) || ...
~all(cp <= c.axpos(3:4)))
return;
end
% set into global structure and show
ne_ui.plotcurves.cpos = cp;
pc_showcursor;
% the button was pressed
if c.btdwn
pc_handlemove;
end
% handle move
function pc_handlemove
global ne_ui;
c = ne_ui.plotcurves;
% only handle one event
if c.hevnt
return;
end
ne_ui.plotcurves.hevnt = true;
% spot
if ~isempty(c.spota)
% get curve number
csel = c.hTag.LB_plotcurves_curves.Value;
if isempty(csel) || ...
csel <= size(c.opts.sets, 1)
ne_ui.plotcurves.hevnt = false;
return;
end
csel = csel - size(c.opts.sets, 1);
% current spot positions
spotp = zeros(numel(c.opts.spot), 2);
for spc = 1:size(spotp, 1)
spotp(spc, :) = c.opts.spot{spc}(csel, 1:2);
end
% what position to put the spot to
spos = pc_axescp(c.cpos);
if ~c.mctrl
if c.spota > 1
spos(1) = max(spotp(c.spota - 1, 1), spos(1));
end
if c.spota < size(spotp, 1)
spos(1) = min(spotp(c.spota + 1, 1), spos(1));
end
end
% force to curve
if c.hTag.CB_plotcurves_focurve.Value > 0
% which data
if c.mshft && ...
~isempty(c.opts.odchannel)
chan = c.opts.odchannel;
else
chan = c.opts.curves{csel, 2}(1);
end
% sample
spos(2) = c.obj.SampleData(chan, spos(1), spos(1), 1, c.freq);
end
% update spot
ne_ui.plotcurves.opts.spot{c.spota}(csel, :) = spos;
% replot spots
pc_showspots(csel);
% recompute variables
pc_compute(csel);
% update variables
varc = ne_ui.plotcurves.varc(csel, :);
for vc = 1:numel(varc)
c.hTag.(sprintf('ED_plotcurves_var%d', vc)).String = ...
sprintf('%g', varc(vc));
end
% zoom
else
% create zoom patch
if isempty(c.zoomp)
% get position
zpos = pc_axescp(c.cpos);
ne_ui.plotcurves.zoomp = ...
plot(c.ax, zpos(ones(1, 5), 1), zpos(ones(1, 5), 2));
set(ne_ui.plotcurves.zoomp, 'Color', [0.5, 0.5, 0.5], 'LineStyle', '--');
ne_ui.plotcurves.hevnt = false;
return;
end
% give correct zoomp position
zpos = pc_axescp(c.cpos);
xd = get(c.zoomp, 'XData');
yd = get(c.zoomp, 'YData');
xd(2:3) = zpos(1);
yd(3:4) = zpos(2);
set(c.zoomp, 'XData', xd, 'YData', yd);
end
ne_ui.plotcurves.hevnt = false;
% handle zoom
function pc_handlezoom
global ne_ui;
c = ne_ui.plotcurves;
% only handle one event
if c.hevnt
return;
end
ne_ui.plotcurves.hevnt = true;
% get two positions
zpos = [pc_axescp(c.cpbtd); pc_axescp(c.cpos)];
minzp = min(zpos);
maxzp = max(zpos);
% set new axes limits
pc_showcurve(([minzp; maxzp])');
% unblock event
ne_ui.plotcurves.hevnt = false;
% handle keyboard input
function pc_keypress(src, ke, varargin)
global ne_ui;
% check src
if numel(src) ~= 1
return;
end
% configuration
c = ne_ui.plotcurves;
axlx = c.axlx;
axly = c.axly;
axdx = axlx(2) - axlx(1);
axdy = axly(2) - axly(1);
hTag = c.hTag;
% get Key and Modifier from keyboard event (see Matlab docu!)
kk = ke.Key;
mn = ke.Modifier;
% determine which modifiers are pressed
km = false(1, 4);
if ~isempty(mn)
try
km = [ ...
any(strcmpi('alt', mn)), ...
any(strcmpi('control', mn)), ...
any(strcmpi('shift', mn)), ...
any(strcmpi('command', mn))];
catch ne_eo;
neuroelf_lasterr(ne_eo);
end
end
% what to do
if ~any(km)
switch lower(kk)
case {'downarrow'}