-
Notifications
You must be signed in to change notification settings - Fork 245
/
pop_chanedit.m
1156 lines (1090 loc) · 61.1 KB
/
pop_chanedit.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
% POP_CHANEDIT - Edit the channel locations structure of an EEGLAB dataset,
% EEG.chanlocs. For structure location and file formats,
% see >> help readlocs
%
% EEG.chanlocs. For structure location and file formats,
% see >> help readlocs
%
% Usage: >> EEG = pop_chanedit( EEG, 'key1', value1, 'key2', value2, ... );
% >> [ chanlocs options ] = pop_chanedit( chanlocs, 'key1', value1);
% >> [ chanlocs chaninfo options ] = pop_chanedit( chanlocs, chaninfo, ...
% 'key1', value1, 'key2', value2, ... );
%
% Graphic interface:
% "Channel information ('field name')" - [edit boxes] display channel field
% contents for the current channel. Command line equivalent
% to modify these fields: 'transform'
% "Opt. 3D center" - [button] optimally re-center 3-D channel coordinates. Uses
% CHANCENTER. Command line equivalent: 'convert', { 'chancenter'
% [xc yc zc] }, [xc yc zc] being the center of the sphere. Use []
% to find the center of the best fitting sphere.
% "Rotate axis" - [button] force one electrode to one position and rotate the other
% electrodes accordingly. Command line equivalent: 'forcelocs'.
% "Transform axis" - [button] perform any operation on channel fields. Command
% line equivalent: 'transform'.
% "Xyz->polar & sph." - [button] convert 3-D cartesian coordinates to polar and
% 3-D spherical coordinates. This is useful when you edit the
% coordinates manually. Command line equivalent: 'convert', 'cart2all'.
% "Sph.->polar & xyz" - [button] convert 3-D spherical coordinates to polar and
% 3-D cartesian coordinates. Command line equivalent: 'convert', 'sph2all'.
% "Polar->sph & xyz" - [button] convert 2-D polar coordinates to 3-D spherical and
% 3-D cartesian coordinates. Command line equivalent: 'convert', 'topo2all'.
% Note that if spherical radii are absent, they are forced to 1.
% "Set head radius" - [button] change head size radius. This is useful
% to make channels location compatible with a specified spherical model.
% Command line equivalent: 'headrad'.
% "Set channel types" - [button] set channel type names for a range of data channels.
% "Delete chan" - [button] delete channel. Command line equivalent: 'delete'.
% "Insert chan" - [button] insert channel before current channel.
% Command line equivalent: 'insert'.
% "<<" - [button] scroll channel backward by 10.
% "<" - [button] scroll channel backward by 1.
% ">" - [button] scroll channel forward by 1.
% ">>" - [button] scroll channel forward by 10.
% "Append chan" - [button] append channel after the current channel.
% Command line equivalent: 'append'.
% "Plot 2D" - [button] plot channel locations in 2-D using TOPOPLOT
% "Plot radius [value (0.2-1.0), []=auto)" - [edit box] default plotting radius
% in 2-D polar views. This does NOT affect channel locations; it
% is only used for visualization. This parameter is attached to the
% chanlocs structure and is then used in all 2-D scalp topoplots.
% Default -> to data limits. Command line equivalent: 'plotrad'.
% "Nose along +X" - [list] Indicate the direction of the nose. This information
% is used in functions like TOPOPLOT, HEADPLOT and DIPPLOT.
% Command line equivalent: 'nosedir'.
% "Plot 3D" - [button] plot channel positions in 3-D using PLOTCHANS3D
% "Read locations" - [button] read location file using READLOCS
% Command line equivalent: 'load'.
% "Read help" - [button] display READLOCS function help.
% "Save .ced" - [button] save channel locations in native EEGLAB ".ced" format.
% Command line equivalent: 'save'.
% "Save others" - [button] save channel locations in other formats using
% POP_WRITELOCS (see READLOCS for available channel formats).
% "Cancel" - [button] cancel all editing.
% "Help" - [button] display this help message.
% "OK" - [button] save edits and propagate to parent.
%
% Inputs:
% EEG - EEG dataset
% chanlocs - EEG.chanlocs structure
%
% Optional inputs:
% 'convert' - {conversion_type [args]} Conversion type may be: 'cart2topo'
% 'sph2topo', 'topo2sph', 'sph2cart', 'cart2sph', or 'chancenter'.
% See help messages for these functions. Args are only relevant
% for 'chancenter'. More info is given in the graphic interface
% description above.
% 'transform' - String command for manipulating arrays. 'chan' is full channel
% info. Fields that can be manipulated are 'labels', 'theta'
% 'radius' (polar angle and radius), 'X', 'Y', 'Z' (cartesian
% 3-D) or 'sph_theta', 'sph_phi', 'sph_radius' for spherical
% horizontal angle, azimuth and radius.
% Ex: 'chans(3) = chans(14)', 'X = -X' or a multi-step transform
% with steps separated by ';': Ex. 'TMP = X; X = Y; Y = TMP'
% 'changechan' - {number value1 value2 value3 ...} Change the values of all fields
% for the given channel number, minimally {num label theta radius}.
% Ex: 'changechan' {12 'PXz' -90 0.30}
% 'changefield' - {number field value} Change field value for channel number number.
% Ex: {34 'theta' 320.4}.
% 'insert' - {number 'labels' value 'theta' value 'radius' value 'X' value 'Y' ...
% value 'Z' value 'sph_theta' value 'sph_phi' value 'sph_radius' ...
% value 'type' value 'datachan' value }
% Insert new channel and specified values before the current channel
% number. If the number of values is less than 10, remaining
% fields will be 0. (Previously, this parameter was termed 'add').
% 'append' - Same as 'insert' (above) but insert the the new channel after
% the current channel number.
% 'delete' - [int_vector] Vector of channel numbers to delete.
% 'forcelocs' - [cell] call FORCELOCS to force a particular channel to be at a
% particular location on the head sphere; rotate other channels
% accordingly.
% 'skirt' - Topographical polar skirt factor (see >> help topoplot)
% 'shrink' - Topographical polar shrink factor (see >> help topoplot)
% 'load' - [filename|{filename, 'key', 'val'}] Load channel location file
% optional arguments (such as file format) to the function
% READLOCS can be specified if the input is a cell array.
% 'save' - 'filename' Save text file with channel info.
% 'eval' - [string] evaluate string ('chantmp' is the name of the channel
% location structure).
% 'headrad' - [float] change head radius.
% 'lookup' - [string] look-up channel numbers for standard locations in the
% channel location file given as input.
% 'rplurchanloc' - [1,0] [1] Replace EEG.urchanlocs.If EEG.urchanlocs is empty this
% option will be ignored and will be set to [1]
% 'addfiducials' - ['on'|'off'] add fiducials if they are not present.
% 'cleanlabels' - ['on'|'off'] remove quotes, space characters and reference
% from channel labels. Default is 'no'.
%
% Outputs:
% EEG - new EEGLAB dataset with updated channel location structures
% EEG.chanlocs, EEG.urchanlocs, EEG.chaninfo
% chanlocs - updated channel location structure
% chaninfo - updated chaninfo structure
% options - structure containing plotting options (equivalent to EEG.chaninfo)
%
% Ex: EEG = pop_chanedit(EEG,'load', { 'dummy.elp' 'elp' }, 'delete', [3 4], ...
% 'convert', { 'xyz->polar' [] -1 1 }, 'save', 'mychans.loc' )
% % Load polhemus file, delete two channels, convert to polar (see
% % CART2TOPO for arguments) and save into 'mychans.loc'.
%
% Author: Arnaud Delorme, CNL / Salk Institute, 20 April 2002
%
% See also: READLOCS
% Copyright (C) Arnaud Delorme, CNL / Salk Institute, 15 March 2002, 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.
% hidden parameter
% 'gui' - [figure value], allow to process the same dialog box several times
function [chansout, chaninfo, urchans, com] = pop_chanedit(chans, orichaninfo, varargin)
urchans = [];
com ='';
if nargin < 1
help pop_chanedit;
return;
end
chansout = chans;
chaninfo = [];
fig = [];
if nargin < 2
orichaninfo = [];
end
if isempty(chans) || all(~ishandle(chans))
% in case an EEG structure was given as input
% -------------------------------------------
if isfield(chans, 'chanlocs')
% process multiple datasets
if length(chans) > 1
sameAsFirst = arrayfun(@(x)isequaln(chans(1).chanlocs, x.chanlocs), chans(2:end));
if ~all(sameAsFirst)
warning( [ 'Datasets do not have the exact same channel structure.' ] );
end
% pop up GUI for first dataset
EEG = chans(1);
if isempty(varargin)
[~, chaninfo, urchans, com] = pop_chanedit(EEG, orichaninfo, varargin{:});
else
com = sprintf('EEG = pop_chanedit(EEG, ''%s'', %s);', orichaninfo, vararg2str(varargin));
end
if isequal(com, 'EEG=pop_chanedit(EEG, []);')
return
end
% Apply to all datasets and resave if necessary
if isempty(com), return; end
eeglab_options
for iDat = 1:length(chans)
EEG = chans(iDat);
eval(com);
EEG.saved = 'no';
if option_storedisk
EEG = pop_saveset(EEG, 'savemode', 'resave');
EEG = update_datafield(EEG);
end
chans = eeg_store(chans, EEG, iDat);
if option_storedisk
chans(iDat).saved = 'yes'; % eeg_store by default set it to no
end
end
chansout = chans;
return;
end
dataset_input = 1;
EEG = chans;
chans = EEG(1).chanlocs;
nchansori = EEG.nbchan;
if isfield(EEG, 'chaninfo')
chaninfo = EEG(1).chaninfo;
else chaninfo = [];
end
if isfield(EEG, 'urchanlocs')
urchans = EEG(1).urchanlocs;
end
else
nchansori = 0;
dataset_input = 0;
chaninfo = orichaninfo;
end
% dealing with additional parameters
% ----------------------------------
if nargin > 1 && ~ischar(orichaninfo), % nothing
if nargin > 2
if ~ischar(varargin{1})
urchans = varargin{1};
varargin = varargin(2:end);
end
end
elseif nargin > 1 && ~isempty(orichaninfo) && ischar(orichaninfo)
varargin = { orichaninfo varargin{:} };
if isequal(orichaninfo, chaninfo)
chaninfo = [];
end
orichaninfo = [];
end
% insert "no data channels" in channel structure
% ----------------------------------------------
nbchan = length(chans);
[tmp, chaninfo, chans] = eeg_checkchanlocs(chans, chaninfo);
if isfield(chaninfo, 'shrink') && ~isempty(chaninfo.shrink)
icadefs;
if SHRINKWARNING
warndlg2( [ 'You are currently shrinking channel locations for display.' 10 ...
'A new option (more anatomically correct) is to plot channels' 10 ...
'outside head limits so the shrink option has been disabled.' 10 ...
'(Edit the icadefs file to disable this message)' ], 'Shrink factor warning');
end
end
oldchaninfo = chaninfo;
end
% Checking for flag to replace 'urchanloc' field
indx_tmp = find(strcmp(varargin,'rplurchanloc'));
flag_replurchan = 0;
if ~isempty(indx_tmp)
flag_replurchan = varargin{indx_tmp+1};
end
if nargin < 3 && isstruct(chans)
totaluserdat = {};
% lookup channel locations if necessary
% -------------------------------------
if ~all(cellfun('isempty', {chans.labels})) && all(cellfun('isempty', {chans.theta}))
[chans chaninfo urchans com] = pop_chanedit(chans, chaninfo, 'lookupgui', []);
for index = 1:length(chans)
chans(index).ref = '';
chans(index).datachan = 1;
end
if ~isempty(com)
totaluserdat = { com };
%[chans chaninfo urchans com] = pop_chanedit(chans, chaninfo, com{:});
end
end
commentfields = { 'Channel label ("label")', ...
'Polar angle ("theta")', 'Polar radius ("radius")', ...
'Cartesian X ("X")', ...
'Cartesian Y ("Y")', ...
'Cartesian Z ("Z")', ...
'Spherical horiz. angle ("sph_theta")', ...
'Spherical azimuth angle ("sph_phi")', ...
'Spherical radius ("sph_radius")' ...
'Channel type' 'Reference' ...
'Index in backup ''urchanlocs'' structure' ...
'Channel in data array (set=yes)' };
% add field values
% ----------------
geometry = { 1 };
tmpstr = sprintf('Channel information ("field_name"):');
uilist = { { 'Style', 'text', 'string', tmpstr, 'fontweight', 'bold' } };
uiconvert = { ...
{ 'Style', 'pushbutton', 'string', 'Opt. head center', 'callback', 'pop_chanedit(gcbf, [], ''chancenter'', []);' } ...
{ 'Style', 'pushbutton', 'string', 'Rotate axis' , 'callback', 'pop_chanedit(gcbf, [], ''forcelocs'', []);' } ...
{ 'Style', 'pushbutton', 'string', 'Transform axes' , 'callback', 'pop_chanedit(gcbf, [], ''transform'', []);' } ...
{ }, ...
{ 'Style', 'pushbutton', 'string', 'xyz -> polar & sph.', 'callback', 'pop_chanedit(gcbf, [], ''convert'', {''cart2all''});' }, ...
{ 'Style', 'pushbutton', 'string', 'sph. -> polar & xyz', 'callback', 'pop_chanedit(gcbf, [], ''convert'', {''sph2all'' });' }, ...
{ 'Style', 'pushbutton', 'string', 'polar -> sph. & xyz', 'callback', 'pop_chanedit(gcbf, [], ''convert'', {''topo2all''});' }, ...
{ }, ...
{ 'Style', 'pushbutton', 'string', 'Set head radius', 'callback', 'pop_chanedit(gcbf, [], ''headrad'', []);' } ...
{ 'Style', 'pushbutton', 'string', 'Set channel types', 'callback', 'pop_chanedit(gcbf, [], ''settype'', []);' } ...
{ 'Style', 'pushbutton', 'string', 'Set reference', 'callback', 'pop_chanedit(gcbf, [], ''setref'' , []);' } ...
{ } { } };
% create text and edit for each field
% -----------------------------------
allfields = { 'labels' 'theta' 'radius' 'X' 'Y' 'Z' 'sph_theta' 'sph_phi' 'sph_radius' 'type' 'ref' 'urchan' 'datachan' };
for index = 1:length(allfields)-1
cbfield = [ 'valnumtmp = str2num(get(findobj(gcbf, ''tag'', ''chaneditnumval''), ''string''));' ...
'pop_chanedit(gcbf, [], ''changefield'', { valnumtmp ''' allfields{index} ''' get(gcbo, ''string'') });' ...
'clear valnumtmp;' ];
geometry = { geometry{:} [1.5 1 0.2 1] };
uilist = { uilist{:}, ...
{ 'Style', 'text', 'string', commentfields{index} }, ...
{ 'Style', 'edit', 'tag', [ 'chanedit' allfields{index} ], 'string', ...
num2str(getfield(chans,{1}, allfields{index})), 'horizontalalignment', 'center', 'callback', cbfield } ...
{ } uiconvert{index} };
end
% special checkbox for chandata field
% -----------------------------------
geometry = { geometry{:} [2 0.35 0.5 1] };
cbfield = [ 'valnumtmp = str2num(get(findobj(gcbf, ''tag'', ''chaneditnumval''), ''string''));' ...
'pop_chanedit(gcbf, [], ''changefield'', { valnumtmp ''' allfields{end} ''' get(gcbo, ''value'') });' ...
'clear valnumtmp;' ];
uilist = { uilist{:}, ...
{ 'Style', 'text', 'string', commentfields{end} }, ...
{ 'Style', 'checkbox', 'tag', [ 'chanedit' allfields{end}], 'string', '' 'value', 1 'callback', cbfield } { } uiconvert{end} };
% add buttons
% -----------
geometry = { geometry{:} [1] [1.15 0.5 0.6 1.9 0.4 0.4 1.15] [1.15 0.7 0.7 1 0.7 0.7 1.15] };
cb_del = [ 'valnum = str2num(char(get(findobj(gcbf,''tag'', ''chaneditnumval''), ''string'')));' ...
'pop_chanedit(gcbf, [], ''deletegui'', valnum);' ];
cb_insert = [ 'valnum = str2num(char(get(findobj(gcbf,''tag'', ''chaneditnumval''), ''string'')));' ...
'pop_chanedit(gcbf, [], ''insert'', valnum);' ];
cb_append = [ 'valnum = str2num(char(get(findobj(gcbf,''tag'', ''chaneditnumval''), ''string'')));' ...
'pop_chanedit(gcbf, [], ''append'', valnum);' ];
uilist = { uilist{:}, ...
{ }, ...
{ 'Style', 'pushbutton', 'string', 'Delete chan', 'callback', cb_del }, ...
{ },{ }, ...
{ 'Style', 'text' , 'string', ['Channel number (of ' int2str(length(chans)) ')'], ...
'fontweight', 'bold', 'tag', 'chaneditscantitle' }, { },{ },{ }, ...
{ 'Style', 'pushbutton', 'string', 'Insert chan', 'callback', cb_insert } ...
{ 'Style', 'pushbutton', 'string', '<<', 'callback', [ 'pop_chanedit(gcbf, [], ''movecursor'', -10);' ] } ...
{ 'Style', 'pushbutton', 'string', '<', 'callback', [ 'pop_chanedit(gcbf, [], ''movecursor'', -1);' ] } ...
{ 'Style', 'edit' , 'string', '1', 'tag', 'chaneditnumval', 'callback', [ 'pop_chanedit(gcbf, []);' ] } ...
{ 'Style', 'pushbutton', 'string', '>', 'callback', [ 'pop_chanedit(gcbf, [], ''movecursor'', 1);' ] } ...
{ 'Style', 'pushbutton', 'string', '>>', 'callback', [ 'pop_chanedit(gcbf, [], ''movecursor'', 10);' ] } ...
{ 'Style', 'pushbutton', 'string', 'Append chan', 'callback', cb_append }, ...
};
% add sorting options
% -------------------
cb_rplurchan = [ 'valnumtmp = get(findobj(gcbf, ''tag'', ''rplurchan''), ''value'');' ...
'pop_chanedit(gcbf, [], ''rplurchanloc'', valnumtmp);' ...
'clear valnumtmp;' ];
noseparam = strmatch(upper(chaninfo.nosedir), { '+X' '-X' '+Y' '-Y' });
if isempty(noseparam), error('Wrong value for nose direction'); end
geometry = { geometry{:} [1] [0.9 1.3 0.6 1.1 0.9] [1] [1 1 1 1 1] [1]};
uilist = { uilist{:},...
{ } ...
{ 'Style', 'pushbutton', 'string', 'Plot 2-D', 'callback', 'pop_chanedit(gcbf, [], ''plot2d'', []);' },...
{ 'Style', 'text', 'string', 'Plot radius (0.2-1, []=auto)'} ...
{ 'Style', 'edit', 'string', char(chaninfo.plotrad), 'tag', 'plotrad' 'callback' 'pop_chanedit(gcbf, [], ''plotrad'', []);' } ...
{ 'Style', 'popupmenu', 'string', 'Nose along +X|Nose along -X|Nose along +Y|Nose along -Y', ...
'tag' 'nosedir' 'value',noseparam, 'callback' 'pop_chanedit(gcbf,[],''nosedir'',[]);' 'listboxtop' noseparam } ...
{ 'Style', 'pushbutton', 'string', 'Plot 3-D (xyz)', 'callback', 'pop_chanedit(gcbf, [], ''plot3d'', []);' } ...
{}, ...
{ 'Style', 'pushbutton', 'string', 'Read locations', 'callback', 'pop_chanedit(gcbf,[],''load'',[]);' }, ...
{ 'Style', 'pushbutton', 'string', 'Read locs help', 'callback', 'pophelp(''readlocs.m'');' }, ...
{ 'Style', 'pushbutton', 'string', 'Look up locs', 'callback', 'pop_chanedit(gcbf,[], ''lookupgui'', []);' }, ...
{ 'Style', 'pushbutton', 'string', 'Save (as .ced)', 'callback', 'pop_chanedit(gcbf,[], ''save'',[]);' } ...
{ 'Style', 'pushbutton', 'string', 'Save (other types)', 'callback', 'pop_chanedit(gcbf,[], ''saveothers'',[]);' } ...
{ 'Style', 'checkbox' , 'string', 'Overwrite Original Channels', 'callback', cb_rplurchan, 'tag' , 'rplurchan', 'value', flag_replurchan }...
};
% evaluation of command below is required to center text (if
% declared a text instead of edit, the uicontrol is not centered)
comeval = [ 'set(findobj( ''tag'', ''chanediturchan''), ''style'', ''text'', ''backgroundcolor'', [.66 .76 1] );' ...
'set(findobj( ''tag'', ''chaneditref''), ''style'', ''text'', ''backgroundcolor'', [.66 .76 1] );' ...
'set(findobj( ''tag'', ''ok''), ''callback'', ''valnumtmp = get(findobj(gcbf, ''''tag'''', ''''rplurchan''''), ''''value''''); pop_chanedit(gcbf, [],''''rplurchanloc'''',valnumtmp, ''''return'''', []);'')' ];
userdata.chans = chans;
userdata.nchansori = nchansori;
userdata.chaninfo = chaninfo;
userdata.urchans = urchans ;
userdata.commands = totaluserdat;
[results userdata returnmode] = inputgui( 'geometry', geometry, 'uilist', uilist, 'helpcom', ...
'pophelp(''pop_chanedit'');', 'title', 'Edit channel info -- pop_chanedit()', ...
'userdata', userdata, 'eval' , comeval );
if length(results) == 0,
com = '';
if dataset_input, chansout = EEG; end;
return;
end
% transfer events back from global workspace
chans = userdata.chans;
chaninfo = userdata.chaninfo;
urchans = userdata.urchans;
if ~isempty(userdata.commands)
com = sprintf('%s=pop_chanedit(%s, %s);', inputname(1), inputname(1), vararg2str(userdata.commands));
end
% Updating flag
flag_replurchan = results{15};
else
% call from command line or from a figure
% ---------------------------------------
currentpos = 0;
if ishandle(chans)
fig = chans;
userdata = get(fig, 'userdata');
chans = userdata.chans;
nchansori = userdata.nchansori;
chaninfo = userdata.chaninfo;
urchans = userdata.urchans;
currentpos = str2num(get(findobj(fig, 'tag', 'chaneditnumval'), 'string'));
end
args = varargin;
% no interactive inputs
% scan all the fields of g
% ------------------------
for curfield = 1:2:length(args)
switch lower(args{curfield})
case 'cleanlabels'
for iChan = 1:length(chans)
posMinus = find(chans(iChan).labels == '-');
if ~isempty(posMinus)
chans(iChan).labels = chans(iChan).labels(1:posMinus(1)-1);
end
end
case 'rplurchanloc'
if flag_replurchan, urchans = eeg_checkchanlocs(chans, chaninfo); end
args{curfield} = 'rplurchanloc';
args{ curfield+1 } = flag_replurchan;
case 'return'
[tmpchans] = eeg_checkchanlocs(chans);
if nchansori ~= 0 && nchansori ~= length(tmpchans)
if ~popask(strvcat(['The number of data channels (' int2str(length(tmpchans)) ') not including fiducials does not'], ...
['correspond to the initial number of channels (' int2str(nchansori) '), so for consistency purposes'], ...
'new channel information will be ignored if this function was called from EEGLAB', ...
'If you have added a reference channel manually, check the "Data channel" checkbox is off'))
else
set(findobj(fig, 'tag', 'ok'), 'userdata', 'stop');
end
else
set(findobj(fig, 'tag', 'ok'), 'userdata', 'stop');
end
args = {};
case 'plot3d', % GUI only
tmpind = find(~cellfun('isempty', { chans.X }));
if ~isempty(tmpind),
plotchans3d([ [ chans(tmpind).X ]' [ chans(tmpind).Y ]' [ chans(tmpind).Z ]'], { chans(tmpind).labels });
else disp('cannot plot: no XYZ coordinates');
end
args = {};
case 'plot2d', % GUI only
plotrad = str2num(get(findobj(fig, 'tag', 'plotrad'), 'string'));
figure; topoplot([],chans, 'style', 'blank', 'drawaxis', 'on', 'electrodes', ...
'labelpoint', 'plotrad', plotrad, 'chaninfo', chaninfo);
args = {};
case 'movecursor', % GUI only
currentpos = max(1,min(currentpos+args{curfield+1},length(chans)));
args = {};
case 'plotrad',
if isempty( args{curfield+1} )
args{curfield+1} = str2num(get(findobj(fig, 'tag', 'plotrad'), 'string'));
end
chaninfo.plotrad = args{curfield+1};
case 'forcelocs',
if ~isempty(fig) % GUI BASED
[ comtmp tmpforce ] = forcelocs(chans);
if ~isempty(tmpforce),
args{curfield+1} = tmpforce{1};
end
end
if ~isempty(args{curfield+1})
chans = forcelocs(chans,args{curfield+1});
disp('Convert XYZ coordinates to spherical and polar');
end
case 'chancenter',
if ~isempty(fig)
[chans newcenter tmpcom] = pop_chancenter(chans);
args{curfield } = 'eval';
args{curfield+1} = tmpcom;
end
case 'convert',
if iscell(args{curfield+1})
method=args{curfield+1}{1};
extraargs = args{curfield+1}(2:end);
else
method=args{curfield+1};
extraargs = {''};
end
if ~isempty(fig) && ~strcmp(method, 'chancenter')
tmpButtonName=questdlg2( strvcat('This will modify fields in the channel structure', ...
'Are you sure you want to apply this function ?'), 'Confirmation', 'Cancel', 'Yes','Yes');
if ~strcmpi(tmpButtonName, 'Yes'), return; end
end
switch method
case 'chancenter',
if isempty(extraargs)
[X Y Z]=chancenter( [chans.X ]', [ chans.Y ]', [ chans.Z ]',[]);
else
[X Y Z]=chancenter( [chans.X ]', [ chans.Y ]', [ chans.Z ]', extraargs{:});
end
if isempty(X), return; end
for index = 1:length(chans)
chans(index).X = X(index);
chans(index).Y = Y(index);
chans(index).Z = Z(index);
end
disp('Note: automatically convert XYZ coordinates to spherical and polar');
chans = convertlocs(chans, 'cart2all');
otherwise
chans = convertlocs(chans, method, 'verbose', 'on');
end
case 'settype'
if ~isempty(fig)
args{curfield+1} = inputdlg2({'Channel indices' 'Type (e.g. EEG)' }, ...
'Set channel type', 1, { '' '' }, 'pop_chanedit');
end
try, tmpchans = args{curfield+1}{1}; tmptype = args{curfield+1}{2};catch, return; end
if isempty(tmpchans) && isempty(tmptype), return; end
if ischar(tmpchans)
tmpchans = eval( [ '[' tmpchans ']' ], 'settype: error in channel indices');
end
if ~ischar(tmptype), tmptype = num2str(tmptype); end
for index = 1:length(tmpchans)
if tmpchans(index) > 0 && tmpchans(index) <= length(chans)
chans( tmpchans(index) ).type = tmptype;
end
end
case 'setref'
if ~isempty(fig)
disp('Note that setting the reference only changes the reference labels');
disp('Use the re-referencing menu to change the reference');
args{curfield+1} = inputdlg2({'Channel indices' 'Reference (e.g. Cz)' }, ...
'Set channel reference', 1, { '' '' }, 'pop_chanedit');
end
try, tmpchans = args{curfield+1}{1}; tmpref = args{curfield+1}{2};catch, return; end
if isempty(tmpchans) && isempty(tmpref), return; end
if ischar(tmpchans)
tmpchans = eval( [ '[' tmpchans ']' ], 'settype: error in channel indices');
end
if ~ischar(tmpref), tmpref = num2str(tmpref); end
for index = 1:length(tmpchans)
if tmpchans(index) > 0 && tmpchans(index) <= length(chans)
chans( tmpchans(index) ).ref = tmpref;
end
end
case 'transform'
if ~isempty(fig)
args{curfield+1} = inputdlg2({'Enter transform: (Ex: TMP=X; X=-Y; Y=TMP or Y(3) = X(2), etc.' }, ...
'Transform', 1, { '' }, 'pop_chanedit');
end
try, tmpoper = args{curfield+1}; catch, return; end
if isempty(deblank(tmpoper)), return; end
if iscell(tmpoper), tmpoper = tmpoper{1}; end
tmpoper = [ tmpoper ';' ];
[eloc, labels, theta, radius, indices] = readlocs(chans);
if isempty(findstr(tmpoper, 'chans'))
try,
X = [ chans(indices).X ];
Y = [ chans(indices).Y ];
Z = [ chans(indices).Z ];
sph_theta = [ chans(indices).sph_theta ];
sph_phi = [ chans(indices).sph_phi ];
sph_radius = [ chans(indices).sph_radius ];
eval(tmpoper);
for ind = 1:length(indices)
chans(indices(ind)).X = X(min(length(X),ind));
chans(indices(ind)).Y = Y(min(length(Y),ind));
chans(indices(ind)).Z = Z(min(length(Z),ind));
chans(indices(ind)).theta = theta(min(length(theta),ind));
chans(indices(ind)).radius = radius(min(length(radius),ind));
chans(indices(ind)).sph_theta = sph_theta(min(length(sph_theta),ind));
chans(indices(ind)).sph_phi = sph_phi(min(length(sph_phi),ind));
chans(indices(ind)).sph_radius = sph_radius(min(length(sph_radius),ind));
end
if ~isempty(findstr(tmpoper, 'X')), chans = convertlocs(chans, 'cart2all'); end
if ~isempty(findstr(tmpoper, 'Y')), chans = convertlocs(chans, 'cart2all'); end
if ~isempty(findstr(tmpoper, 'Z')), chans = convertlocs(chans, 'cart2all'); end
if ~isempty(findstr(tmpoper, 'sph_theta')), chans = convertlocs(chans, 'sph2all');
elseif ~isempty(findstr(tmpoper, 'theta')), chans = convertlocs(chans, 'topo2all'); end
if ~isempty(findstr(tmpoper, 'sph_phi')), chans = convertlocs(chans, 'sph2all'); end
if ~isempty(findstr(tmpoper, 'sph_radius')), chans = convertlocs(chans, 'sph2all');
elseif ~isempty(findstr(tmpoper, 'radius')), chans = convertlocs(chans, 'topo2all'); end
catch, disp('Unknown error when applying transform'); end
else
eval(tmpoper);
end
case 'headrad'
if ~isempty(fig) % GUI
tmpres = inputdlg2({'Enter new head radius (same unit as DIPFIT head model):' }, ...
'Head radius', 1, { '' }, 'pop_chanedit');
if ~isempty(tmpres),
args{ curfield+1 } = str2num(tmpres{1});
else return;
end
end
if ~isempty( args{ curfield+1 } )
allrad = [ chans.sph_radius ];
if length(unique(allrad)) == 1 % already spherical
chans = pop_chanedit(chans, 'transform', [ 'sph_radius = ' num2str( args{ curfield+1 } ) ';' ]);
else % non-spherical, finding best match
factor = args{ curfield+1 } / mean(allrad);
chans = pop_chanedit(chans, 'transform', [ 'sph_radius = sph_radius*' num2str( factor ) ';' ]);
disp('Warning: electrodes do not lie on a sphere. Sphere model fitting for');
disp(' dipole localization will work but generate many warnings');
end
chans = convertlocs(chans, 'sph2all');
end
case 'shrink'
chans(1).shrink = args{ curfield+1 };
case 'deletegui'
chans(args{ curfield+1 })=[];
currentpos = min(length(chans), currentpos);
args{ curfield } = 'delete';
case 'delete'
chans(args{ curfield+1 })=[];
case 'changefield'
tmpargs = args{ curfield+1 };
if length( tmpargs ) < 3
error('pop_chanedit: not enough arguments to change field value');
end
if ~isempty(strmatch( tmpargs{2}, { 'X' 'Y' 'Z' 'theta' 'radius' 'sph_theta' 'sph_phi' 'sph_radius'}))
if ~isnumeric(tmpargs{3}), tmpargs{3} = str2num(tmpargs{3}); end
end
for paramChan = 2:2:length(tmpargs)
eval([ 'chans(' int2str(tmpargs{1}) ').' tmpargs{paramChan} '=' reformat(tmpargs{paramChan+1} ) ';' ]);
end
case { 'insert' 'add' 'append' }
tmpargs = args{ curfield+1 };
allfields = fieldnames(chans);
if isnumeric(tmpargs)
tmpargs2{1} = tmpargs;
tmpargs = tmpargs2;
end
num = tmpargs{1};
if strcmpi(args{curfield}, 'append')
num=num+1;
currentpos = currentpos+1;
end
chans(end+1).label = '';
tmpChan = chans(end);
chans(num+1:end) = chans(num:end-1);
chans(num) = tmpChan;
for index = 2:2:length( tmpargs )
chans = setfield(chans, {num}, tmpargs{index}, tmpargs{index+1});
end
if isfield(chans, 'datachan')
if isempty(chans(num).datachan)
chans(num).datachan = 0;
end
end
case 'changechan'
tmpargs = args{ curfield+1 };
num = tmpargs{1};
allfields = fieldnames(chans);
if length( tmpargs ) < length(allfields)+1
error('pop_chanedit: not enough arguments to change all field values');
end
for index = 1:length( allfields )
eval([ 'chans(' int2str(num) ').' allfields{index} '=' reformat(tmpargs{index+1}) ';' ]);
end
case 'load'
if ~isempty(fig) % GUI
[tmpf tmpp] = uigetfile('*.*', 'Load a channel location file');
drawnow;
if ~isequal(tmpf, 0),
tmpformats = readlocs('getinfos');
tmpformattype = { 'autodetect' tmpformats(1:end-1).type };
tmpformatstr = { 'autodetect' tmpformats(1:end-1).typestring };
tmpformatdesc = { 'Autodetect file format from file extension' tmpformats(1:end-1).description };
%cb_listbox = 'tmpdesc=get(gcbf, ''userdata''); set(findobj(gcbf, ''tag'', ''strdesc''), ''string'', strmultiline([ ''File format: '' tmpdesc{get(gcbo, ''value'')} ], 30, 10)); clear tmpdesc;'' } }, ''pophelp(''''readlocs'''')'',' ...
% 'Read electrode file'', tmpformatdesc, ''normal'', 4);
%txtgui = [ strmultiline([ 'File format: Autodetect file format from file extension'], 20, 10) 10 10 ];
%tmpfmt = inputgui( 'geometry', {[1 1]}, ...
% 'uilist' , { { 'style', 'text', 'string', txtgui 'tag' 'strdesc' }, ...
% { 'style', 'listbox', 'string', strvcat(tmpformatstr) 'callback' '' } }, ...
% 'geomvert', [10], ...
% 'helpcom' , 'pophelp(''readlocs'');');
tmpfmt = inputgui( 'geometry', {[1 1 1] [1]}, ...
'uilist' , { { 'style', 'text', 'string', 'File format:' 'tag' 'strdesc' } {} {}, ...
{ 'style', 'listbox', 'string', strvcat(tmpformatstr) 'callback' '' } }, ...
'geomvert', [1 8], ...
'helpcom' , 'pophelp(''readlocs'');');
if isempty(tmpfmt),
args{ curfield+1 } = [];
else args{ curfield+1 } = { fullfile(tmpp, tmpf) 'filetype' tmpformattype{tmpfmt{1}} };
end
else args{ curfield+1 } = [];
end
end
tmpargs = args{ curfield+1 };
if ~isempty(tmpargs),
if ischar(tmpargs)
[chans] = readlocs(tmpargs);
[tmp tmp2 chans] = eeg_checkchanlocs(chans);
chaninfo = [];
chaninfo.filename = tmpargs;
else
[chans] = readlocs(tmpargs{:});
[tmp tmp2 chans] = eeg_checkchanlocs(chans);
chaninfo = [];
chaninfo.filename = tmpargs{1};
end
% backup file content etc...
% --------------------------
tmptext = loadtxt( chaninfo.filename, 'delim', [], 'verbose', 'off', 'convert', 'off');
chaninfo.filecontent = strvcat(tmptext{:});
% set urchan structure
% --------------------
urchans = chans;
for index = 1:length(chans)
chans(index).urchan = index;
end
end
if ~isfield(chans, 'datachan')
chans(1).datachan = [];
end
for index = 1:length(chans)
if isempty(chans(index).datachan)
chans(index).datachan = 1;
end
end
case 'eval'
tmpargs = args{ curfield+1 };
eval(tmpargs);
case 'saveothers'
com = pop_writelocs(chans);
args{ curfield } = 'eval';
args{ curfield+1 } = com;
case 'addfiducials'
% do nothing (already handled)
case 'save'
if ~isempty(fig)
[tmpf tmpp] = uiputfile('*.ced', 'Save channel locs in EEGLAB .ced format');
drawnow;
args{ curfield+1 } = fullfile(tmpp, tmpf);
end
tmpargs = args{ curfield+1 };
[tmp, tmp, filext] = fileparts(tmpargs);
if isempty(tmpargs), return; end
fid = fopen(tmpargs, 'w');
if fid ==-1, error('Cannot open file'); end
allfields = fieldnames(chans);
fields = { 'labels' 'theta' 'radius' 'X' 'Y' 'Z' 'sph_theta' 'sph_phi' 'sph_radius' 'type' };
tmpdiff = setdiff(fields, allfields);
if ~isempty(tmpdiff), error(sprintf('Field "%s" missing in channel location structure', tmpdiff{1})); end
if strcmpi(filext,'.ced')
origfield = fields; % Setting the order as expected in readlocs.m
else
origfield = intersect(allfields,fields,'stable'); % Getting the original order from file
end
fprintf(fid, 'Number\t');
for field = 1:length(fields)
fprintf(fid, '%s\t', origfield{field});
end
fprintf(fid, '\n');
for index=1:length(chans)
fprintf(fid, '%d\t', index);
for field = 1:length(fields)
tmpval = getfield(chans, {index}, origfield{field});
if ischar(tmpval)
fprintf(fid, '%s\t', tmpval);
else
fprintf(fid, '%3.3g\t', tmpval);
end
end
fprintf(fid, '\n');
end
if isempty(tmpargs), chantmp = readlocs(tmpargs); end
case 'nosedir'
nosevals = { '+X' '-X' '+Y' '-Y' };
if ~isempty(fig)
tmpval = get(findobj(gcbf, 'tag', 'nosedir'), 'value');
args{ curfield+1 } = nosevals{tmpval};
warndlg2( [ 'Changing the nose direction will force EEGLAB to physically rotate ' 10 ...
'electrodes, so next time you call this interface, nose direction will' 10 ...
'be +X. If your electrodes are currently aligned with a specific' 10 ...
'head model, you will have to rotate them in the model coregistration' 10 ...
'interface to realign them with the model.'], 'My Warn Dialog');
end
chaninfo.nosedir = args{ curfield+1 };
if isempty(strmatch(chaninfo.nosedir, nosevals))
error('Wrong value for nose direction');
end
case 'lookupgui'
standardchans = { 'Fp1' 'Fpz' 'Fp2' 'Nz' 'AF9' 'AF7' 'AF3' 'AFz' 'AF4' 'AF8' 'AF10' 'F9' 'F7' 'F5' ...
'F3' 'F1' 'Fz' 'F2' 'F4' 'F6' 'F8' 'F10' 'FT9' 'FT7' 'FC5' 'FC3' 'FC1' 'FCz' 'FC2' ...
'FC4' 'FC6' 'FT8' 'FT10' 'T9' 'T7' 'C5' 'C3' 'C1' 'Cz' 'C2' 'C4' 'C6' 'T8' 'T10' ...
'TP9' 'TP7' 'CP5' 'CP3' 'CP1' 'CPz' 'CP2' 'CP4' 'CP6' 'TP8' 'TP10' 'P9' 'P7' 'P5' ...
'P3' 'P1' 'Pz' 'P2' 'P4' 'P6' 'P8' 'P10' 'PO9' 'PO7' 'PO3' 'POz' 'PO4' 'PO8' 'PO10' ...
'O1' 'Oz' 'O2' 'O9' 'O10' 'CB1' 'CB2' 'Iz' };
for indexchan = 1:length(chans)
if isempty(chans(indexchan).labels), chans(indexchan).labels = ''; end
end
tmp1 = intersect_bc( lower(standardchans), {chans.labels});
if ~isempty(tmp1) || isfield(chans, 'theta')
% adding fiducials if they are not llaready present
% -------------------------------------------------
indFid = strmatch('addfiducials', args(1:2:end), 'exact');
if isempty(indFid) || ~strcmpi(args{indFid+1}, 'no')
if isfield(chans, 'type')
% check if fiducial are present
allTypes = lower(cellfun(@char, { chans.type }, 'UniformOutput',false));
if ~isempty(strmatch('fid', allTypes))
disp('Skipped adding fiducials (they are already present)');
elseif ~isempty(strmatch('nasion', lower({ chans.labels })))
disp('Skipped adding fiducials (they are already present)');
elseif ~isempty(strmatch('nz', lower({ chans.labels })))
disp('Skipped adding fiducials (they are already present)');
else
chans(end+1).labels = 'Nz';
chans(end).type = 'FID';
chans(end).datachan = false;
chans(end+1).labels = 'LPA';
chans(end).type = 'FID';
chans(end).datachan = false;
chans(end+1).labels = 'RPA';
chans(end).type = 'FID';
chans(end).datachan = false;
end
end
end
% finding template location files
% -------------------------------
dipfitdefs;
[~,fileNameBESA] = fileparts(template_models(1).chanfile);
[~,fileNameBEM ] = fileparts(template_models(2).chanfile);
eeglabp = fileparts(which('eeglab.m'));
chantemplate(1).name = fileNameBESA;
chantemplate(1).filename = template_models(1).chanfile;
chantemplate(1).description = 'use BESA file for 4-shell dipfit spherical model';
chantemplate(2).name = fileNameBEM;
chantemplate(2).filename = template_models(2).chanfile;
chantemplate(2).description = 'use MNI coordinate file for BEM dipfit model';
chantemplate(3).name = 'Standard-10-5-Cap385_witheog.elp';
chantemplate(3).filename = fullfile(eeglabp,'functions','supportfiles', 'Standard-10-5-Cap385_witheog.elp');
chantemplate(3).description = 'use BESA file and look up EOG channels';
try
chantemplate = add_locfiles(chantemplate, 'eeglab', 'eeglab', 'EEGLAB ');
chantemplate = add_locfiles(chantemplate, 'eeglab', 'philips_neuro', 'Magstim/EGI');
chantemplate = add_locfiles(chantemplate, 'eeglab', 'besa_egi', 'BESA or EGI legacy');
chantemplate = add_locfiles(chantemplate, 'eeglab', 'neuroscan', 'Neuroscan');
chantemplate = add_locfiles(chantemplate, 'fieldtrip', 'electrode', 'Fieldtrip ');
chantemplate = add_locfiles(chantemplate, 'fieldtrip', 'layout', 'Fieldtrip layout');
catch
fprintf(2, 'Warning: issue with looking up channel location files\n');
end
% other commands for help/load
% ----------------------------
comhelp = [ 'warndlg2(strvcat(''The template file depends on the model'',' ...
'''you intend to use for dipole fitting. The default file is fine for'',' ...
'''spherical model.'');' ];
commandload = [ '[filename, filepath] = uigetfile(''*'', ''Select a text file'');' ...
'if filename ~=0,' ...
' set(findobj(''parent'', gcbf, ''tag'', ''elec''), ''string'', [ filepath filename ]);' ...
'end;' ...
'clear filename filepath tagtest;' ];
setmodel = [ 'tmpdat = get(gcbf, ''userdata'');' ...
'tmpval = get(gcbo, ''value'');' ...
'set(findobj(gcbf, ''tag'', ''elec''), ''string'', tmpdat(tmpval).filename);' ...
'clear tmpval tmpdat;' ];
if ~isfield(chans, 'theta'), message =1;
elseif all(cellfun('isempty', {chans.theta })), message =1;
else message =2;
end
if message == 1
textcomment = strvcat('Only channel labels are present currently, but some of these labels have known', ...
'positions. Do you want to look up coordinates for these channels using the electrode', ...
'file below? If you have a channel location file for this dataset, press cancel, then', ...
'use button "Read location" in the following gui. If you do not know, just press OK.');
else
textcomment = strvcat('Some channel labels may have known locations.', ...
'Do you want to look up coordinates for these channels using the electrode', ...
'file below? If you do not know, press OK.');
end
uilist = { { 'style' 'text' 'string' textcomment } ...
{ 'style' 'popupmenu' 'string' { chantemplate.description } ...
'callback' setmodel 'value' 2 } ...
{ } ...
{ 'style' 'edit' 'string' chantemplate(2).filename 'tag' 'elec' } ...
{ 'style' 'pushbutton' 'string' '...' 'callback' commandload } ...
{ } ...
{ 'style' 'checkbox' 'string' 'Import file instead and erase all channels' } ...
{ } };
% { 'Style', 'checkbox', 'value', 0, 'string','Overwrite Original Channels' } };
res = inputgui( { 1 [1 0.3] [1 0.3] 1 1 1 }, uilist, 'pophelp(''pop_chanedit'')', 'Look up channel locations?', chantemplate, 'normal', [3 1 1 1 1 1] );
if ~isempty(res)
chaninfo.filename = res{2};
if res{3}
args{ curfield } = 'load';
else
args{ curfield } = 'lookup';
end
args{ curfield+1 } = res{2};
com = args;
% there are 2 version of chans, chaninfo
% - one where all channels are in chans (input below)
% - one where some are in chainfo (output of pop_chanedit)
[chans, chaninfo] = pop_chanedit(chans, chaninfo, args{ curfield }, args{ curfield+1 });
[~, chaninfo, chans] = eeg_checkchanlocs(chans, chaninfo); % insert "data_chan" back in channel structure and move chaninfo channels in chans
else
return;
end
end
case 'lookup'
chaninfo.filename = args{ curfield+1 };
if strcmpi(chaninfo.filename, 'standard-10-5-cap385.elp')
dipfitdefs;
chaninfo.filename = template_models(1).chanfile;
elseif strcmpi(chaninfo.filename, 'standard_1005.elc')
dipfitdefs;
chaninfo.filename = template_models(2).chanfile;
elseif strcmpi(chaninfo.filename, 'standard_1005.ced')
dipfitdefs;
chaninfo.filename = template_models(2).chanfile;
end
tmplocs = readlocs( char(chaninfo.filename), 'defaultelp', 'BESA' );
for indexchan = 1:length(chans)
if isempty(chans(indexchan).labels), chans(indexchan).labels = ''; end
end
[tmp, ind1, ind2] = intersect_bc(lower({ tmplocs.labels }), lower({ chans.labels }));
if ~isempty(tmp)
chans = struct('labels', { chans.labels }, 'datachan', { chans.datachan }, 'type', { chans.type });
[ind2, ind3] = sort(ind2);
ind1 = ind1(ind3);
if isempty(ind2)
fprintf(2, 'Warning: No channel with the same label found in this file\n');
else
fprintf('%d channel with the same label found and imported\n', length(ind1));
end
for index = 1:length(ind2)
chans(ind2(index)).theta = tmplocs(ind1(index)).theta;
chans(ind2(index)).radius = tmplocs(ind1(index)).radius;
chans(ind2(index)).X = tmplocs(ind1(index)).X;
chans(ind2(index)).Y = tmplocs(ind1(index)).Y;
chans(ind2(index)).Z = tmplocs(ind1(index)).Z;
chans(ind2(index)).sph_theta = tmplocs(ind1(index)).sph_theta;
chans(ind2(index)).sph_phi = tmplocs(ind1(index)).sph_phi;
chans(ind2(index)).sph_radius = tmplocs(ind1(index)).sph_radius;