-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy patheegplot.m
2211 lines (2001 loc) · 92 KB
/
eegplot.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
% EEGPLOT - Scroll (horizontally and/or vertically) through multichannel data.
% Allows vertical scrolling through channels and manual marking
% and unmarking of data stretches or epochs for rejection.
% Usage:
% >> eegplot(data, 'key1', value1 ...); % use interface buttons, etc.
%
% Menu items:
% "Figure > print" - [menu] Print figure in portrait or landscape.
% "Figure > Edit figure" - [menu] Remove menus and buttons and call up the standard
% Matlab figure menu. Select "Tools > Edit" to format the figure
% for publication. Command line equivalent: 'noui'
% "Figure > Accept and Close" - [menu] Same as the bottom-right "Reject" button.
% "Figure > Cancel and Close" - [menu] Cancel all editing, same as the "Cancel" button.
% "Display > Marking color" > [Hide|Show] marks" - [menu] Show or hide patches of
% background color behind the data. Mark stretches of *continuous*
% data (e.g., for rejection) by dragging the mouse horizontally
% over the activity. With *epoched* data, click on the selected epochs.
% Clicked on a marked region to unmark it. Called from the
% command line, marked data stretches or epochs are returned in
% the TMPREJ variable in the global workspace *if/when* the "Reject"
% button is pressed (see Outputs); called from POP_EEGPLOT or
% EEGLAB, the marked data portions are removed from the current
% dataset, and the dataset is automatically updated.
% "Display > Marking color > Choose color" - [menu] Change the background marking
% color. The marking color(s) of previously marked trials are preserved.
% Called from command line, subsequent functions EEGPLOT2EVENT or
% EEGPLOT2TRIALS allow processing trials marked with different colors
% in the TMPREJ output variable. Command line equivalent: 'wincolor'.
% "Display > Grid > ..." - [menu] Toggle (on or off) time and/or channel axis grids
% in the activity plot. Submenus allow modifications to grid aspects.
% Command line equivalents: 'xgrid' / 'ygrid'
% "Display > Show scale" - [menu] Show (or hide if shown) the scale on the bottom
% right corner of the activity window. Command line equivalent: 'scale'
% "Display > Title" - [menu] Change the title of the figure. Command line equivalent:
% 'title'
% "Settings > Time range to display" - [menu] For continuous EEG data, this item
% pops up a query window for entering the number of seconds to display
% in the activity window. For epoched data, the query window asks
% for the number of epochs to display (this can be fractional).
% Command line equivalent: 'winlength'
% "Settings > Number of channels to display" - [menu] Number of channels to display
% in the activity window. If not all channels are displayed, the
% user may scroll through channels using the slider on the left
% of the activity plot. Command line equivalent: 'dispchans'
% "Settings > Channel labels > ..." - [menu] Use numbers as channel labels or load
% a channel location file from disk. If called from the EEGLAB menu or
% POP_EEGPLOT, the channel labels of the dataset will be used.
% Command line equivalent: 'eloc_file'
% "Settings > Zoom on/off" - [menu] Toggle Matlab figure zoom on or off for time and
% electrode axes. left-click to zoom (x2); right-click to reverse-zoom.
% Else, draw a rectangle in the activity window to zoom the display into
% that region. NOTE: When zoom is on, data cannot be marked for rejection.
% "Settings > Events" - [menu] Toggle event on or off (assuming events have been
% given as input). Press "legend" to pop up a legend window for events.
%
% Display window interface:
% "Activity plot" - [main window] This axis displays the channel activities. For
% continuous data, the time axis shows time in seconds. For epoched
% data, the axis label indicate time within each epoch.
% "Cancel" - [button] Closes the window and cancels any data rejection marks.
% "Event types" - [button] pop up a legend window for events.
% "<<" - [button] Scroll backwards though time or epochs by one window length.
% "<" - [button] Scroll backwards though time or epochs by 0.2 window length.
% "Navigation edit box" - [edit box] Enter a starting time or epoch to jump to.
% ">" - [button] Scroll forward though time or epochs by 0.2 window length.
% ">>" - [button] Scroll forward though time or epochs by one window length.
% "Chan/Time/Value" - [text] If the mouse is within the activity window, indicates
% which channel, time, and activity value the cursor is closest to.
% "Scale edit box" - [edit box] Scales the displayed amplitude in activity units.
% Command line equivalent: 'spacing'
% "+ / -" - [buttons] Use these buttons to +/- the amplitude scale by 10%.
% "Reject" - [button] When pressed, save rejection marks and close the figure.
% Optional input parameter 'command' is evaluated at that time.
% NOTE: This button's label can be redefined from the command line
% (see 'butlabel' below). If no processing command is specified
% for the 'command' parameter (below), this button does not appear.
% "Stack/Spread" - [button] "Stack" collapses all channels/activations onto the
% middle axis of the plot. "Spread" undoes the operation.
% "Norm/Denorm" - [button] "Norm" normalizes each channel separately such that all
% channels have the same standard deviation without changing original
% data/activations under EEG structure. "Denorm" undoes the operation.
%
% Required command line input:
% data - Input data matrix, either continuous 2-D (channels,timepoints) or
% epoched 3-D (channels,timepoints,epochs). If the data is preceded
% by keyword 'noui', GUI control elements are omitted (useful for
% plotting data for presentation). A set of power spectra at
% each channel may also be plotted (see 'freqlimits' below).
% Optional command line keywords:
% 'srate' - Sampling rate in Hz {default|0: 256 Hz}
% 'spacing' - Display range per channel (default|0: max(whole_data)-min(whole_data))
% 'eloc_file' - Electrode filename (as in >> topoplot example) to read
% ascii channel labels. Else,
% [vector of integers] -> Show specified channel numbers. Else,
% [] -> Do not show channel labels {default|0 -> Show [1:nchans]}
% 'limits' - [start end] Time limits for data epochs in ms (for labeling
% purposes only).
% 'freqs' - Vector of frequencies (If data contain spectral values).
% size(data, 2) must be equal to size(freqs,2).
% *** This option must be used ALWAYS with 'freqlimits' ***
% 'freqlimits' - [freq_start freq_end] If plotting epoch spectra instead of data, frequency
% limits to display spectrum. (Data should contain spectral values).
% *** This option must be used ALWAYS with 'freqs' ***
% 'winlength' - [value] Seconds (or epochs) of data to display in window {default: 5}
% 'time' [value in second] Time to plot. Default is the
% beginning of the data.
% 'dispchans' - [integer] Number of channels to display in the activity window
% {default: from data}. If < total number of channels, a vertical
% slider on the left side of the figure allows vertical data scrolling.
% 'title' - Figure title {default: none}
% 'plottitle' - Plot title {default: none}
% 'xgrid' - ['on'|'off'] Toggle display of the x-axis grid {default: 'off'}
% 'ygrid' - ['on'|'off'] Toggle display of the y-axis grid {default: 'off'}
% 'ploteventdur' - ['on'|'off'] Toggle display of event duration { default: 'off' }
% 'data2' - [float array] identical size to the original data and
% plotted on top of it.
%
% Additional keywords:
% 'command' - ['string'] Matlab command to evaluate when the 'REJECT' button is
% clicked. The 'REJECT' button is visible only if this parameter is
% not empty. As explained in the "Output" section below, the variable
% 'TMPREJ' contains the rejected windows (see the functions
% EEGPLOT2EVENT and EEGPLOT2TRIAL).
% 'butlabel' - Reject button label. {default: 'REJECT'}
% 'winrej' - [start end R G B e1 e2 e3 ...] Matrix giving data periods to mark
% for rejection, each row indicating a different period
% [start end] = period limits (in frames from beginning of data);
% [R G B] = specifies the marking color;
% [e1 e2 e3 ...] = a (1,nchans) logical [0|1] vector giving
% channels (1) to mark and (0) not mark for rejection.
% 'color' - ['on'|'off'|cell array] Plot channels with different colors.
% If an RGB cell array {'r' 'b' 'g'}, channels will be plotted
% using the cell-array color elements in cyclic order {default:'off'}.
% 'wincolor' - [color] Color to use to mark data stretches or epochs {default:
% [ 0.7 1 0.9] is the default marking color}
% 'events' - [struct] EEGLAB event structure (EEG.event) to use to show events.
% 'submean' - ['on'|'off'] Remove channel means in each window {default: 'on'}
% 'position' - [lowleft_x lowleft_y width height] Position of the figure in pixels.
% 'tag' - [string] Matlab object tag to identify this EEGPLOT window (allows
% keeping track of several simultaneous EEGPLOT windows).
% 'children' - [integer] Figure handle of a *dependent* EEGPLOT window. Scrolling
% horizontally in the master window will produce the same scroll in
% the dependent window. Allows comparison of two concurrent datasets,
% or of channel and component data from the same dataset.
% 'scale' - ['on'|'off'] Display the amplitude scale {default: 'on'}.
% 'mocap' - ['on'|'off'] Display motion capture data in a separate figure.
% To run, select an EEG data period in the scrolling display using
% the mouse. Motion capture (mocap) data should be
% under EEG.moredata.mocap.markerPosition in xs, ys and zs fields which are
% (number of markers, number of time points) arrays.
% {default: 'off'}.
% 'selectcommand' - [cell array] list of 3 commands (strings) to run when the mouse
% button is down, when it is moving and when the mouse button is up.
% 'ctrlselectcommand' - [cell array] same as above in conjunction with pressing the
% CTRL key.
% 'noui' - ['on'|'off'] Remove user interface for printing {default: 'off'}
%
% Outputs:
% TMPREJ - Matrix (same format as 'winrej' above) placed as a variable in
% the global workspace (only) when the REJECT button is clicked.
% The command specified in the 'command' keyword argument can use
% this variable. (See EEGPLOT2TRIAL and EEGPLOT2EVENT).
%
% Author: Arnaud Delorme & Colin Humphries, CNL/Salk Institute, SCCN/INC/UCSD, 1998-2001
%
% See also: EEG_MULTIEEGPLOT, EEGPLOT2EVENT, EEGPLOT2TRIAL, EEGLAB
% deprecated
% 'colmodif' - nested cell array of window colors that may be marked/unmarked. Default
% is current color only.
% Copyright (C) 2001 Arnaud Delorme & Colin Humphries, Salk Institute, arno@salk.edu
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. 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.
%
% 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 HOLDER OR CONTRIBUTORS 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.
% Note for programmers - Internal variable structure:
% All in g. except for Eposition and Eg.spacingwhich are inside the boxes
% gcf
% 1 - winlength
% 2 - srate
% 3 - children
% 'backeeg' axis
% 1 - trialtag
% 2 - g.winrej
% 3 - nested call flag
% 'eegaxis'
% 1 - data
% 2 - colorlist
% 3 - submean % on or off, subtract the mean
% 4 - maxfreq % empty [] if no gfrequency content
% 'buttons hold other informations' Eposition for instance hold the current position
function [outvar1] = eegplot(data, varargin)
FORCE_EEGPLOT_LEGACY = false; % change to true here if you experience problems
persistent message;
outvar1 = [];
[~,versiont] = version;
if datenum(versiont) <= 737315 || FORCE_EEGPLOT_LEGACY % Matlab 2018b and earlier
[outvar1] = eegplotlegacy(data, varargin{:});
if isempty(message)
message = 1;
disp('Because you are using Matlab 2018b or earlier, you are using eegplotlegacy');
end
return
end
if isempty(message)
message = 1;
fprintf('You are using a new version of eegplot - if you encounter problems\ntype "edit eegplot.m" and change FORCE_EEGPLOT_LEGACY to true\n');
end
% Defaults (can be re-defined):
DEFAULT_PLOT_COLOR = { [0 0 1], [0.7 0.7 0.7]}; % EEG line color
try, icadefs;
DEFAULT_FIG_COLOR = BACKCOLOR;
BUTTON_COLOR = GUIBUTTONCOLOR;
catch
DEFAULT_FIG_COLOR = [1 1 1];
BUTTON_COLOR =[0.8 0.8 0.8];
end
DEFAULT_AXIS_COLOR = 'k'; % X-axis, Y-axis Color, text Color
DEFAULT_GRID_SPACING = 1; % Grid lines every n seconds
DEFAULT_GRID_STYLE = '-'; % Grid line style
YAXIS_NEG = 'off'; % 'off' = positive up
DEFAULT_NOUI_PLOT_COLOR = 'k'; % EEG line color for noui option
% 0 - 1st color in AxesColorOrder
SPACING_EYE = 'on'; % g.spacingI on/off
SPACING_UNITS_STRING = ''; % '\muV' for microvolt optional units for g.spacingI Ex. uV
%MAXEVENTSTRING = 10;
%DEFAULT_AXES_POSITION = [0.0964286 0.15 0.842 0.75-(MAXEVENTSTRING-5)/100];
% dimensions of main EEG axes
ORIGINAL_POSITION = [50 50 800 500];
matVers = version;
matVers = str2double(matVers(1:3));
if nargin < 1
help eegplot
return
end
% %%%%%%%%%%%%%%%%%%%%%%%%
% Setup inputs
% %%%%%%%%%%%%%%%%%%%%%%%%
if ~ischar(data) % If NOT a 'noui' call or a callback from uicontrols
try
options = varargin;
if ~isempty( varargin )
for i = 1:2:numel(options)
g.(options{i}) = options{i+1};
end
else g= []; end
catch
disp('eegplot() error: calling convention {''key'', value, ... } error'); return;
end
% Selection of data range If spectrum plot
if isfield(g,'freqlimits') || isfield(g,'freqs')
% % Check consistency of freqlimits
% % Check consistency of freqs
% Selecting data and freqs
[~, fBeg] = min(abs(g.freqs-g.freqlimits(1)));
[~, fEnd] = min(abs(g.freqs-g.freqlimits(2)));
data = data(:,fBeg:fEnd,:);
g.freqs = g.freqs(fBeg:fEnd);
% Updating settings
if ndims(data) == 2, g.winlength = g.freqs(end) - g.freqs(1); end
g.srate = length(g.freqs)/(g.freqs(end)-g.freqs(1));
g.isfreq = 1;
end
% push button: create/remove window
% ---------------------------------
defdowncom = 'eegplot(''defdowncom'', gcbf);'; % push button: create/remove window
defmotioncom = 'eegplot(''defmotioncom'', gcbf);'; % motion button: move windows or display current position
defupcom = 'eegplot(''defupcom'', gcbf);';
defctrldowncom = 'eegplot(''topoplot'', gcbf);'; % CTRL press and motion -> do nothing by default
defctrlmotioncom = ''; % CTRL press and motion -> do nothing by default
defctrlupcom = ''; % CTRL press and up -> do nothing by default
try, g.srate; catch, g.srate = 256; end
try, g.spacing; catch, g.spacing = 0; end
try, g.eloc_file; catch, g.eloc_file = 0; end % 0 mean numbered
try, g.winlength; catch, g.winlength = 5; end % Number of seconds of EEG displayed
try, g.position; catch, g.position = ORIGINAL_POSITION; end
try, g.title; catch, g.title = ['Scroll activity -- eegplot()']; end
try, g.plottitle; catch, g.plottitle = ''; end
try, g.trialstag; catch, g.trialstag = -1; end
try, g.winrej; catch, g.winrej = []; end
try, g.command; catch, g.command = ''; end
try, g.tag; catch, g.tag = 'EEGPLOT'; end
try, g.xgrid; catch, g.xgrid = 'off'; end
try, g.ygrid; catch, g.ygrid = 'off'; end
try, g.color; catch, g.color = 'off'; end
try, g.submean; catch, g.submean = 'off'; end
try, g.children; catch, g.children = 0; end
try, g.limits; catch, g.limits = [0 1000*(size(data,2)-1)/g.srate]; end
try, g.freqs; catch, g.freqs = []; end % Ramon
try, g.freqlimits; catch, g.freqlimits = []; end
try, g.dispchans; catch, g.dispchans = size(data,1); end
try, g.wincolor; catch, g.wincolor = [ 0.7 1 0.9]; end
try, g.butlabel; catch, g.butlabel = 'REJECT'; end
try, g.colmodif; catch, g.colmodif = { g.wincolor }; end
try, g.scale; catch, g.scale = 'on'; end
try, g.events; catch, g.events = []; end
try, g.ploteventdur; catch, g.ploteventdur = 'off'; end
try, g.data2; catch, g.data2 = []; end
try, g.plotdata2; catch, g.plotdata2 = 'off'; end
try, g.mocap; catch, g.mocap = 'off'; end % nima
try, g.selectcommand; catch, g.selectcommand = { defdowncom defmotioncom defupcom }; end
try, g.ctrlselectcommand; catch, g.ctrlselectcommand = { defctrldowncom defctrlmotioncom defctrlupcom }; end
try, g.datastd; catch, g.datastd = []; end %ozgur
try, g.normed; catch, g.normed = 0; end %ozgur
try, g.envelope; catch, g.envelope = 0; end %ozgur
try, g.maxeventstring; catch, g.maxeventstring = 10; end % JavierLC
try, g.isfreq; catch, g.isfreq = 0; end % Ramon
try, g.noui; catch, g.noui = 'off'; end
try, g.time; catch, g.time = []; end
if strcmpi(g.ploteventdur, 'on'), g.ploteventdur = 1; else g.ploteventdur = 0; end
if ndims(data) > 2
g.trialstag = size( data, 2);
end
gfields = fieldnames(g);
for index=1:length(gfields)
switch gfields{index}
case {'spacing', 'srate' 'eloc_file' 'winlength' 'position' 'title' 'plottitle' ...
'trialstag' 'winrej' 'command' 'tag' 'xgrid' 'ygrid' 'color' 'colmodif'...
'freqs' 'freqlimits' 'submean' 'children' 'limits' 'dispchans' 'wincolor' ...
'maxeventstring' 'ploteventdur' 'butlabel' 'scale' 'events' 'data2' 'plotdata2' ...
'mocap' 'selectcommand' 'ctrlselectcommand' 'datastd' 'normed' 'envelope' 'isfreq' 'noui' 'time' },;
otherwise, error(['eegplot: unrecognized option: ''' gfields{index} '''' ]);
end
end
% g.data=data; % never used and slows down display dramatically - Ozgur 2010
if length(g.srate) > 1
disp('Error: srate must be a single number'); return;
end
if length(g.spacing) > 1
disp('Error: ''spacing'' must be a single number'); return;
end
if length(g.winlength) > 1
disp('Error: winlength must be a single number'); return;
end
if ischar(g.title) > 1
disp('Error: title must be is a string'); return;
end
if ischar(g.command) > 1
disp('Error: command must be is a string'); return;
end
if ischar(g.tag) > 1
disp('Error: tag must be is a string'); return;
end
if length(g.position) ~= 4
disp('Error: position must be is a 4 elements array'); return;
end
switch lower(g.xgrid)
case { 'on', 'off' },;
otherwise disp('Error: xgrid must be either ''on'' or ''off'''); return;
end
switch lower(g.ygrid)
case { 'on', 'off' },;
otherwise disp('Error: ygrid must be either ''on'' or ''off'''); return;
end
switch lower(g.submean)
case { 'on' 'off' };
otherwise disp('Error: submean must be either ''on'' or ''off'''); return;
end
switch lower(g.scale)
case { 'on' 'off' };
otherwise disp('Error: scale must be either ''on'' or ''off'''); return;
end
if ~iscell(g.color)
switch lower(g.color)
case 'on', g.color = { 'k', 'm', 'c', 'b', 'g' };
case 'off', g.color = { [ 0 0 0.4] };
otherwise
disp('Error: color must be either ''on'' or ''off'' or a cell array');
return;
end
end
if length(g.dispchans) > size(data,1)
g.dispchans = size(data,1);
end
if ~iscell(g.colmodif)
g.colmodif = { g.colmodif };
end
if g.maxeventstring>20 % JavierLC
disp('Error: maxeventstring must be equal or lesser than 20'); return;
end
if isempty(g.time)
g.time = fastif(g.trialstag(1) == -1, 0, 1);
end
% max event string; JavierLC
% ---------------------------------
MAXEVENTSTRING = g.maxeventstring;
DEFAULT_AXES_POSITION = [0.0964286 0.15 0.842 0.75-(MAXEVENTSTRING-5)/100];
% convert color to modify into array of float
% -------------------------------------------
for index = 1:length(g.colmodif)
if iscell(g.colmodif{index})
tmpcolmodif{index} = g.colmodif{index}{1} ...
+ g.colmodif{index}{2}*10 ...
+ g.colmodif{index}{3}*100;
else
tmpcolmodif{index} = g.colmodif{index}(1) ...
+ g.colmodif{index}(2)*10 ...
+ g.colmodif{index}(3)*100;
end
end
g.colmodif = tmpcolmodif;
[g.chans,g.frames, tmpnb] = size(data);
g.frames = g.frames*tmpnb;
if g.spacing == 0
maxindex = min(1000, g.frames);
stds = std(data(:,1:maxindex),[],2);
g.datastd = stds;
stds = sort(stds);
if length(stds) > 2
stds = mean(stds(2:end-1));
else
stds = mean(stds);
end
g.spacing = stds*3;
if g.spacing > 10
g.spacing = round(g.spacing);
end
if g.spacing == 0 || isnan(g.spacing)
g.spacing = 1; % default
end
end
% set defaults
% ------------
g.incallback = 0;
g.winstatus = 1;
g.setelectrode = 0;
[g.chans,g.frames,tmpnb] = size(data);
g.frames = g.frames*tmpnb;
g.nbdat = 1; % deprecated
g.elecoffset = 0;
% %%%%%%%%%%%%%%%%%%%%%%%%
% Prepare figure and axes
% %%%%%%%%%%%%%%%%%%%%%%%%
figh = figure('UserData', g,... % store the settings here
'Color',DEFAULT_FIG_COLOR, 'name', g.title,...
'MenuBar','none','tag', g.tag ,'Position',g.position, ...
'numbertitle', 'off', 'visible', 'off', 'Units', 'Normalized');
pos = get(figh,'position'); % plot relative to current axes
q = [pos(1) pos(2) 0 0];
s = [pos(3) pos(4) pos(3) pos(4)]./100;
clf;
% Plot title if provided
if ~isempty(g.plottitle)
h = findobj('tag', 'eegplottitle');
if ~isempty(h)
set(h, 'string',g.plottitle);
else
h = textsc(g.plottitle, 'title');
set(h, 'tag', 'eegplottitle');
end
end
% Background axis
% ---------------
ax0 = axes('tag','backeeg','parent',figh,...
'Position',DEFAULT_AXES_POSITION,...
'Box','off','xgrid','off', 'xaxislocation', 'top', 'Units', 'Normalized');
% Drawing axis
% ---------------
YLabels = num2str((1:g.chans)'); % Use numbers as default
YLabels = flipud(char(YLabels,' '));
ax1 = axes('Position',DEFAULT_AXES_POSITION,...
'userdata', data, ...% store the data here
'tag','eegaxis','parent',figh,...%(when in g, slow down display)
'Box','on','xgrid', g.xgrid,'ygrid', g.ygrid,...
'gridlinestyle',DEFAULT_GRID_STYLE,...
'Ylim',[0 (g.chans+1)*g.spacing],...
'YTick',[0:g.spacing:g.chans*g.spacing],...
'YTickLabel', YLabels,...
'TickLength',[.005 .005],...
'Color','none',...
'XColor',DEFAULT_AXIS_COLOR,...
'YColor',DEFAULT_AXIS_COLOR);
try
set(ax1, 'TickLabelInterpreter', 'none'); % old Matlab 2011
catch, end;
if ischar(g.eloc_file) || isstruct(g.eloc_file) % Read in electrode name
if isstruct(g.eloc_file) && length(g.eloc_file) > size(data,1)
g.eloc_file(end) = []; % common reference channel location
end
eegplot('setelect', g.eloc_file, ax1);
end
% %%%%%%%%%%%%%%%%%%%%%%%%%
% Set up uicontrols
% %%%%%%%%%%%%%%%%%%%%%%%%%
% positions of buttons
posbut(1,:) = [ 0.0464 0.0254 0.0385 0.0339 ]; % <<
posbut(2,:) = [ 0.0924 0.0254 0.0288 0.0339 ]; % <
posbut(3,:) = [ 0.1924 0.0254 0.0299 0.0339 ]; % >
posbut(4,:) = [ 0.2297 0.0254 0.0385 0.0339 ]; % >>
posbut(5,:) = [ 0.1287 0.0203 0.0561 0.0390 ]; % Eposition
posbut(6,:) = [ 0.4744 0.0236 0.0582 0.0390 ]; % Espacing
posbut(7,:) = [ 0.2762 0.01 0.0582 0.0390 ]; % elec
posbut(8,:) = [ 0.3256 0.01 0.0707 0.0390 ]; % g.time
posbut(9,:) = [ 0.4006 0.01 0.0582 0.0390 ]; % value
posbut(14,:) = [ 0.2762 0.05 0.0582 0.0390 ]; % elec tag
posbut(15,:) = [ 0.3256 0.05 0.0707 0.0390 ]; % g.time tag
posbut(16,:) = [ 0.4006 0.05 0.0582 0.0390 ]; % value tag
posbut(10,:) = [ 0.5437 0.0458 0.0275 0.0270 ]; % +
posbut(11,:) = [ 0.5437 0.0134 0.0275 0.0270 ]; % -
posbut(12,:) = [ 0.6 0.02 0.14 0.05 ]; % cancel
posbut(13,:) = [-0.15 0.02 0.07 0.05 ]; % cancel
posbut(17,:) = [-0.06 0.02 0.09 0.05 ]; % events types
posbut(20,:) = [-0.17 0.15 0.015 0.8 ]; % slider
posbut(21,:) = [0.738 0.87 0.06 0.048];%normalize
posbut(22,:) = [0.738 0.93 0.06 0.048];%stack channels(same offset)
posbut(:,1) = posbut(:,1)+0.2;
% Five move buttons: << < text > >>
u(1) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position', posbut(1,:), ...
'Tag','Pushbutton1',...
'string','<<',...
'Callback',['global in_callback;', ...
'if isempty(in_callback);in_callback=1;', ...
' try eegplot(''drawp'',1);', ...
' clear global in_callback;', ...
' catch error_struct;', ...
' clear global in_callback;', ...
' throw(error_struct);', ...
' end;', ...
'else;return;end;']);%James Desjardins 2013/Jan/22
u(2) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position', posbut(2,:), ...
'Tag','Pushbutton2',...
'string','<',...
'Callback',['global in_callback;', ...
'if isempty(in_callback);in_callback=1;', ...
' try eegplot(''drawp'',2);', ...
' clear global in_callback;', ...
' catch error_struct;', ...
' clear global in_callback;', ...
' throw(error_struct);', ...
' end;', ...
'else;return;end;']);%James Desjardins 2013/Jan/22
u(5) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'BackgroundColor',[1 1 1], ...
'Position', posbut(5,:), ...
'Style','edit', ...
'Tag','EPosition',...
'string', num2str(g.time),...
'Callback', 'eegplot(''drawp'',0);' );
u(3) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(3,:), ...
'Tag','Pushbutton3',...
'string','>',...
'Callback',['global in_callback;', ...
'if isempty(in_callback);in_callback=1;', ...
' try eegplot(''drawp'',3);', ...
' clear global in_callback;', ...
' catch error_struct;', ...
' clear global in_callback;', ...
' throw(error_struct);', ...
' end;', ...
'else;return;end;']);%James Desjardins 2013/Jan/22
u(4) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(4,:), ...
'Tag','Pushbutton4',...
'string','>>',...
'Callback',['global in_callback;', ...
'if isempty(in_callback);in_callback=1;', ...
' try eegplot(''drawp'',4);', ...
' clear global in_callback;', ...
' catch error_struct;', ...
' clear global in_callback;', ...
' error(error_struct);', ...
' end;', ...
'else;return;end;']);%James Desjardins 2013/Jan/22
% Text edit fields: ESpacing
u(6) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'BackgroundColor',[1 1 1], ...
'Position', posbut(6,:), ...
'Style','edit', ...
'Tag','ESpacing',...
'string',num2str(g.spacing),...
'Callback', 'eegplot(''draws'',0);' );
% Slider for vertical motion
u(20) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position', posbut(20,:), ...
'Style','slider', ...
'visible', 'off', ...
'sliderstep', [0.9 1], ...
'Tag','eegslider', ...
'callback', [ 'tmpg = get(gcbf, ''userdata'');' ...
'tmpg.elecoffset = get(gcbo, ''value'')*(tmpg.chans-tmpg.dispchans);' ...
'set(gcbf, ''userdata'', tmpg);' ...
'eegplot(''drawp'',0);' ...
'clear tmpg;' ], ...
'value', 0);
% Channels, position, value and tag
u(9) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'BackgroundColor',DEFAULT_FIG_COLOR, ...
'Position', posbut(7,:), ...
'Style','text', ...
'Tag','Eelec',...
'string',' ');
u(10) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'BackgroundColor',DEFAULT_FIG_COLOR, ...
'Position', posbut(8,:), ...
'Style','text', ...
'Tag','Etime',...
'string','0.00');
u(11) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'BackgroundColor',DEFAULT_FIG_COLOR, ...
'Position',posbut(9,:), ...
'Style','text', ...
'Tag','Evalue',...
'string','0.00');
u(14)= uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'BackgroundColor',DEFAULT_FIG_COLOR, ...
'Position', posbut(14,:), ...
'Style','text', ...
'Tag','Eelecname',...
'string','Chan.');
% Values of time/value and freq/power in GUI
if g.isfreq
u15_string = 'Freq';
u16_string = 'Power';
else
u15_string = 'Time';
u16_string = 'Value';
end
u(15) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'BackgroundColor',DEFAULT_FIG_COLOR, ...
'Position', posbut(15,:), ...
'Style','text', ...
'Tag','Etimename',...
'string',u15_string);
u(16) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'BackgroundColor',DEFAULT_FIG_COLOR, ...
'Position',posbut(16,:), ...
'Style','text', ...
'Tag','Evaluename',...
'string',u16_string);
% ESpacing buttons: + -
u(7) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(10,:), ...
'Tag','Pushbutton5',...
'string','+',...
'FontSize',8,...
'Callback','eegplot(''draws'',1)');
u(8) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(11,:), ...
'Tag','Pushbutton6',...
'string','-',...
'FontSize',8,...
'Callback','eegplot(''draws'',2)');
cb_normalize = ['g = get(gcbf,''userdata'');if g.normed, disp(''Denormalizing...''); else, disp(''Normalizing...''); end;'...
'hmenu = findobj(gcf, ''Tag'', ''Normalize_menu'');' ...
'ax1 = findobj(''tag'',''eegaxis'',''parent'',gcbf);' ...
'data = get(ax1,''UserData'');' ...
'if isempty(g.datastd), g.datastd = std(data(:,1:min(1000,g.frames),[],2)); end;'...
'if g.normed, '...
'for i = 1:size(data,1), '...
'data(i,:,:) = data(i,:,:)*g.datastd(i);'...
'if ~isempty(g.data2), g.data2(i,:,:) = g.data2(i,:,:)*g.datastd(i);end;'...
'end;'...
'set(gcbo,''string'', ''Norm'');set(findobj(''tag'',''ESpacing'',''parent'',gcbf),''string'',num2str(g.oldspacing));' ...
'else, for i = 1:size(data,1),'...
'data(i,:,:) = data(i,:,:)/g.datastd(i);'...
'if ~isempty(g.data2), g.data2(i,:,:) = g.data2(i,:,:)/g.datastd(i);end;'...
'end;'...
'set(gcbo,''string'', ''Denorm'');g.oldspacing = g.spacing;set(findobj(''tag'',''ESpacing'',''parent'',gcbf),''string'',''5'');end;' ...
'g.normed = 1 - g.normed;' ...
'eegplot(''draws'',0);'...
'set(hmenu, ''Label'', fastif(g.normed,''Denormalize channels'',''Normalize channels''));' ...
'set(gcbf,''userdata'',g);set(ax1,''UserData'',data);clear ax1 g data;' ...
'eegplot(''drawp'',0);' ...
'disp(''Done.'')'];
% Button for Normalizing data
u(21) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(21,:), ...
'Tag','Norm',...
'string','Norm', 'callback', cb_normalize);
cb_envelope = ['g = get(gcbf,''userdata'');'...
'hmenu = findobj(gcf, ''Tag'', ''Envelope_menu'');' ...
'g.envelope = ~g.envelope;' ...
'set(gcbf,''userdata'',g);'...
'set(gcbo,''string'',fastif(g.envelope,''Spread'',''Stack''));' ...
'set(hmenu, ''Label'', fastif(g.envelope,''Spread channels'',''Stack channels''));' ...
'eegplot(''drawp'',0);clear g;'];
% Button to plot envelope of data
u(22) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(22,:), ...
'Tag','Envelope',...
'string','Stack', 'callback', cb_envelope);
if isempty(g.command), tmpcom = 'fprintf(''Rejections saved in variable TMPREJ\n'');';
else tmpcom = g.command;
end
acceptcommand = [ 'g = get(gcbf, ''userdata'');' ...
'TMPREJ = g.winrej;' ...
'if g.children, delete(g.children); end;' ...
'delete(gcbf);' ...
tmpcom ...
'; clear g;']; % quitting expression
if ~isempty(g.command)
u(12) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(12,:), ...
'Tag','Accept',...
'string',g.butlabel, 'callback', acceptcommand);
end
u(13) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(13,:), ...
'string',fastif(isempty(g.command),'CLOSE', 'CANCEL'), 'callback', ...
[ 'g = get(gcbf, ''userdata'');' ...
'if g.children, delete(g.children); end;' ...
'close(gcbf);'] );
if ~isempty(g.events)
u(17) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(17,:), ...
'string', 'Event types', 'callback', 'eegplot(''drawlegend'', gcbf)');
end
for i = 1: length(u) % Matlab 2014b compatibility
if isprop(eval(['u(' num2str(i) ')']),'Style')
set(u(i),'Units','Normalized');
end
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set up uimenus
% %%%%%%%%%%%%%%%%%%%%%%%%%%%
% Figure Menu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
m(7) = uimenu('Parent',figh,'Label','Figure');
m(8) = uimenu('Parent',m(7),'Label','Print');
uimenu('Parent',m(7),'Label','Edit figure', 'Callback', 'eegplot(''noui'');');
uimenu('Parent',m(7),'Label','Accept and close', 'Callback', acceptcommand );
uimenu('Parent',m(7),'Label','Cancel and close', 'Callback','delete(gcbf)')
% Portrait %%%%%%%%
timestring = ['[OBJ1,FIG1] = gcbo;',...
'PANT1 = get(OBJ1,''parent'');',...