⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pop_chanedit.m

📁 含有多种ICA算法的eeglab工具箱
💻 M
📖 第 1 页 / 共 3 页
字号:
% debug for command line call
%
% Revision 1.37  2002/11/15 01:38:14  scott
% Can not -> cannot
%
% Revision 1.36  2002/11/13 17:44:11  arno
% header edition -sm, ad
%
% Revision 1.35  2002/11/13 17:12:50  scott
% help msg - changechan
%
% Revision 1.34  2002/11/13 16:57:24  scott
% help msg
%
% Revision 1.33  2002/11/13 14:57:54  scott
% help msg edit
%
% Revision 1.32  2002/11/12 23:02:21  arno
% debugging message when number of channel does not match
%
% Revision 1.31  2002/10/23 15:51:35  arno
% more bug fixed
%
% Revision 1.30  2002/10/23 15:21:23  arno
% saving error fixed
%
% Revision 1.29  2002/10/16 16:17:13  arno
% debug command line call
%
% Revision 1.28  2002/10/15 17:06:44  arno
% drawnow
%
% Revision 1.27  2002/10/15 17:02:38  arno
% drawnow
%
% Revision 1.26  2002/10/10 21:17:30  arno
% debug command line call and display (when deleting last channel)
%
% Revision 1.25  2002/09/23 17:57:25  arno
% debug shrink off
%
% Revision 1.24  2002/08/12 21:38:24  arno
% text
%
% Revision 1.23  2002/08/12 21:17:59  arno
% debug
%
% Revision 1.22  2002/08/12 18:50:22  arno
% errordlg2
%
% Revision 1.21  2002/08/12 18:30:05  arno
% quesdlg2
%
% Revision 1.20  2002/08/12 16:43:01  arno
% debug inputdlg2
%
% Revision 1.19  2002/08/12 16:37:24  arno
% inputdlg2
%
% Revision 1.18  2002/08/02 15:41:23  arno
% adding file format input
%
% Revision 1.17  2002/07/30 00:40:48  arno
% debugging shrink
%
% Revision 1.16  2002/06/25 14:27:40  arno
% typo and 3d plot check
%
% Revision 1.15  2002/05/21 20:44:31  scott
% removed ; from evalin() calls -sm
%
% Revision 1.14  2002/05/03 00:49:24  arno
% debugging channel center
%
% Revision 1.13  2002/05/02 23:37:27  scott
% editting -sm
%
% Revision 1.12  2002/05/02 23:35:15  scott
% formula -> transform -sm & ad
%
% Revision 1.11  2002/05/02 23:29:56  scott
% Num -> number -sm
%
% Revision 1.10  2002/05/02 23:18:27  scott
% editting -sm
%
% Revision 1.9  2002/05/02 23:16:44  scott
% editting -sm
%
% Revision 1.8  2002/05/02 23:12:17  arno
% editing text
%
% Revision 1.7  2002/05/02 01:46:03  arno
% debugging for full consistency
%
% Revision 1.6  2002/05/01 19:38:38  arno
% returning shrink factor
%
% Revision 1.5  2002/05/01 03:30:55  arno
% editing interface
%
% Revision 1.4  2002/05/01 03:29:28  arno
% correct typo
%
% Revision 1.3  2002/05/01 03:24:27  arno
% function checkchans
%
% Revision 1.2  2002/05/01 03:22:22  arno
% testelp->plotchans3d
%
% Revision 1.1  2002/05/01 03:14:50  arno
% Initial revision
%

% hidden parameter
%   'gui' - [figure value], allow to process the same dialog box several times

function [chans, com] = pop_chanedit(chans, varargin);

com ='';
if nargin < 1
   help pop_editeventvals;
   return;
end;

% in case an EEG structure was given as input
% -------------------------------------------
if isstruct(chans) & isfield(chans, 'chanlocs')
    chans = chans.chanlocs;
end;

nbchan = length(chans);
allfields = { 'labels' 'theta' 'radius' 'X' 'Y' 'Z' 'sph_theta' 'sph_phi' 'sph_radius' };

if isfield(chans, '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: to do so try disabling the shrink option' 10 ...
                    'by unclicking the ''shrink'' button. (Edit the icadefs file to' 10 ...
                    'disable this message)' ], 'Shrink factor warning');
    end;
end;
[chans shrinkorskirt plotrad]= checkchans(chans, allfields);

if nargin < 2
    
	totaluserdat = {};
    % lookup channel locations if necessary
    % -------------------------------------
    if ~all(cellfun('isempty', {chans.labels})) & all(cellfun('isempty', {chans.theta}))
        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' };
        [tmp1 ind1 ind2] = intersect( lower(standardchans), lower({ chans.labels }));
        if ~isempty(tmp1)
            res = questdlg2(strvcat('Only channel labels are currenlty present but some', ...
                                   'of these labels have standart locations. Do you want to look up', ...
                                   'standard coordinates for these channels?'), 'Look up channel locations?', ...
                           'No', 'Yes', 'Yes');
            if strcmpi(res, 'yes')
                chans = pop_chanedit(chans, 'lookup', []);	
                totaluserdat = { 'lookup' [] };
            end;
        end;
    end;
    
	ingui = 1;
	guimodif = 0;
	while ingui
		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")' };
		% transfer channel to global workspace
		global chantmp;
		chantmp = chans;
		evalin('base', [ 'global chantmp ' ]);
		
		% add field values
		% ----------------
		geometry = { 1 };
		tmpstr = sprintf('Channel information ("field_name"):');
		uilist = { { 'Style', 'text', 'string', tmpstr, 'fontweight', 'bold'  } };
		endgui = 'set(findobj(''parent'', gcbf, ''tag'', ''ok''), ''userdata'', ''stop'');';
		transform = [ 'inputdlg2({''Enter transform: (Ex: TMP=X; X=-Y; Y=TMP or Y(3) = X(2), etc.'' }, ' ...
                      '''Transform'', 1, { '''' }, ''pop_chanedit'');'];
        guicenter = [ '[chantmp newcenter tmpcom] = pop_chancenter(chantmp);' ...
                      'olduserdat = get( gcbf, ''userdata''); if isempty(olduserdat), olduserdat = {}; end;' ...
                      'set( gcbf, ''userdata'', { olduserdat{:} ''eval'', tmpcom });' ...
                      'clear olduserdat tmpcom newcenter; comtmp = {};' endgui ];
        %guicenter = [ '[tmpX tmpY tmpZ newcenter tmpoptim]=chancenter(cell2mat({chanstmp.X})'', ' ...
        %              '               cell2mat({chanstmp.Y})'', cell2mat({chanstmp.Z})'',[]);' ...
        %              'chanstmp = pop_chanedit(chanstmp, ''convert'', { ''chancenter'' newcenter 0 });' ...
        %              'olduserdat = get( gcbf, ''userdata''); if isempty(olduserdat), olduserdat = {}; end;' ...
        %              'if tmpoptim, newcenter = []; end;' ...
        %              'set( gcbf, ''userdata'', { olduserdat{:} ''convert'', { ''chancenter'' newcenter 0 } });' ...
        %              'clear tmpcell olduserdat tmpoptim tpmpX tmpY tmpZ newcenter;' ];

		uiconvert = { { 'Style', 'pushbutton', 'string', 'Opt. 3D center', 'callback', ...
						guicenter }, ...
					  { 'Style', 'pushbutton', 'string', 'Rotate axis'  , 'callback', ...
						['[ comtmp tmpforce ] = forcelocs(chantmp); if ~isempty(tmpforce), ' ...
                         'comtmp = {''forcelocs'' tmpforce{1} }; else comtmp = {''forcelocs'' [] }; end; clear tmpforce;' endgui] }, ...
					  { 'Style', 'pushbutton', 'string', 'Transform axes', 'callback', ...
						['comtmp = {''transform'' ' transform '};' endgui] }, ...
					  {  }, ...
					  { 'Style', 'pushbutton', 'string', 'xyz -> polar & sph.', 'callback', ...
						['comtmp = {''convert'' {''cart2all'' ''gui''}};' endgui] }, ...
					  { 'Style', 'pushbutton', 'string', 'sph. -> polar & xyz', 'callback', ...
						['comtmp = {''convert'' {''sph2all'' ''gui''}};' endgui] }, ...
					  { 'Style', 'pushbutton', 'string', 'polar -> sph. & xyz', 'callback', ...
						['comtmp = {''convert'' {''topo2all'' ''gui''}};' endgui] }, ...
					  {  }, ...
					  { } { } };
		%{ 'Style', 'pushbutton', 'string', 'UNDO LAST ', 'callback', '' } { } { } };
		for index = 1:length(allfields)
			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})), 'callback', ...
						   [ 'valnum   = str2num(get(findobj(''parent'', gcbf, ''tag'', ''chaneditnumval''), ''string''));' ...
							 'editval = get(gcbo, ''string'');' ...
							 'if ~isempty(str2num(editval)), editval = str2num(editval);  end;' ...
							 'eval([ ''chantmp(valnum).' allfields{index} '= editval;'']);' ...
							 'olduserdat = get( gcbf, ''userdata'');' ...
							 'if isempty(olduserdat), olduserdat = {}; end;' ...
							 'set( gcbf, ''userdata'', { olduserdat{:} ''changefield'' { valnum ''' allfields{index} ''' editval }});' ...
							 'clear editval valnum olduserdat;' ] } { } uiconvert{index} };
		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] };
		callpart1 = [ 'valnum   = str2num(char(get(findobj(''tag'', ''chaneditnumval''), ''string'')));' ];
		callpart2 = [ 'set(findobj(''tag'', ''chaneditnumval''), ''string'', num2str(valnum));' ];
		for index = 1:length(allfields)
			callpart2 = [ callpart2  'set(findobj(''tag'', ''chanedit' allfields{index} ...
						  '''), ''string'', num2str(chantmp(valnum).' allfields{index} '));' ];
		end;
		callpart2 = [ callpart2 'set(findobj(''tag'', ''chaneditscantitle''), ' ...
					  '''string'', [''Channel number (of '' int2str(length(chantmp)) '')'']);' ...
                      'set(findobj(''tag'', ''chaneditnumval''), ''string'', int2str(valnum));'  ]; 
		callpart2 = [ callpart2 'clear orivalnum valnum;' ];
		cb_del    = [ callpart1 'orivalnum = valnum; chantmp(valnum) = [];' ...
					'valnum = min(valnum,length(chantmp));' ...
                    'olduserdat = get( gcbf, ''userdata''); if isempty(olduserdat), olduserdat = {}; end;' ...
					'set( gcbf, ''userdata'', { olduserdat{:} ''delete'', orivalnum }); clear olduserdat' callpart2 ];
        cb_insert = [callpart1 ...
					'chantmp(end+3) = chantmp(end);' ...
					'chantmp(valnum+1:end-2) = chantmp(valnum:end-3);' ...
					'chantmp(valnum) = chantmp(end-1);' ...
					'chantmp = chantmp(1:end-2);' ...
					'olduserdat = get( gcbf, ''userdata''); if isempty(olduserdat), olduserdat = {}; end;' ...
					'tmpcell = cell(1,1+length(fieldnames(chantmp))); tmpcell{1} =valnum;' ...
					'set( gcbf, ''userdata'', { olduserdat{:} ''insert'', tmpcell }); clear tmpcell olduserdat' callpart2 ];
        cb_append = [callpart1 ...
					'chantmp(end+3) = chantmp(end);' ...
					'chantmp(valnum+2:end-2) = chantmp(valnum+1:end-3);' ...
					'chantmp(valnum+1) = chantmp(end-1);' ...
					'chantmp = chantmp(1:end-2);' ...
					'olduserdat = get( gcbf, ''userdata''); if isempty(olduserdat), olduserdat = {}; end;' ...
					'tmpcell = cell(1,1+length(fieldnames(chantmp))); tmpcell{1} =valnum;' ...
					'set( gcbf, ''userdata'', { olduserdat{:} ''append'', tmpcell }); valnum = valnum+1; clear tmpcell olduserdat' callpart2 ];
        
		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', [callpart1 'valnum = max(valnum-10,1);' callpart2 ] }, ...
					 { 'Style', 'pushbutton', 'string', '<',  'callback', [callpart1 'valnum = max(valnum-1,1);' callpart2 ] }, ...
					 { 'Style', 'edit'      , 'string', '1', 'tag', 'chaneditnumval', 'callback', ...
					                                [callpart1 'valnum = min(str2num(get(gcbo, ''string'')),length(chantmp));' callpart2 ] }, ...
					 { 'Style', 'pushbutton', 'string', '>',  'callback', [callpart1 'valnum = min(valnum+1,length(chantmp));' callpart2 ] }, ...
					 { 'Style', 'pushbutton', 'string', '>>', 'callback', [callpart1 'valnum = min(valnum+10,length(chantmp));' callpart2 ] }, ...
					 { 'Style', 'pushbutton', 'string', 'Append chan',  'callback', cb_append }, ...
				   };
		
		% add sorting options
		% -------------------
		plot2dcom = [ 'if ~isempty(get(findobj(''parent'', gcbf, ''tag'', ''shrinkfactor''), ''string''))' ...
					  '   plotrad = str2num(get(findobj(''parent'', gcbf, ''tag'', ''shrinkfactor''), ''string''));' ...
                      'else ' ...
                      '   plotrad = [];' ...
					  'end;' ...
                      'if get(findobj(''parent'', gcbf,  ''tag'', ''shrinkbut''), ''value'')' ...
					  '   figure; topoplot([],chantmp, ''style'', ''blank'', ''electrodes'', ''labelpoint'', ''plotrad'', plotrad, ''shrink'', ''auto'');' ...
					  'else ' ...
					  '   figure; topoplot([],chantmp, ''style'', ''blank'', ''electrodes'', ''labelpoint'', ''plotrad'', plotrad);' ...
                      'end; clear plotrad;' ];
		geometry = { geometry{:} [1] [0.9 1.3 0.6 1.1 0.9] [1] [1 1 1 1]};
        guireadlocs = [ '[tmpf tmpp] = uigetfile(''*'', ''Load a channel location file''); drawnow;' ...
                        'if ~isequal(tmpf, 0),' ...
                        '   tmpformats = { ''autodetect'', ''loc eeglab'', ''sph eeglab'', ''sfp egi/besa'', ''xyz eeglab'', ''asc neuroscan'', ' ...
                        '         ''dat neuroscan'', ''elc (eetrak)'', ''polhemusx (elp)'', ''polhemusy (elp)'', ''besa (elp)'', ''chanedit (ced)'' };' ...
                        '   tmpfmt = inputgui({[1 1]}, { { ''style'', ''text'', ''string'', [ ''File format'' 10 10 10 10 ] },' ...
                        '            { ''style'', ''listbox'', ''string'', strvcat(tmpformats) }}, ''pophelp(''''readlocs'''')'',' ...
                        '            ''Read electrode file'', [], ''normal'', 4);' ...
						'   if isempty(tmpfmt), comtmp = {''load'' [] };' ...
						'   else comtmp = {''load'' { [tmpp tmpf ] ''filetype'' tmpformats{tmpfmt{1}} } };' ... 
                        '   end; clear tmpfmt tmpp tmpf tmpformats;' ...
                        'else comtmp = {''load'' [] };' ...
                        'end;' endgui ];
        plot3d =     [ 'tmpind = find(~cellfun(''isempty'', { chantmp.X }));' ...
					   'if ~isempty(tmpind),' ...
                       '   plotchans3d([cell2mat({chantmp(tmpind).X})'' cell2mat({chantmp(tmpind).Y})'' cell2mat({chantmp(tmpind).Z})''],' ...
					                   '{chantmp(tmpind).labels}); else disp(''cannot plot: no XYZ coordinates'');' ...
                       'end;' ];
		uilist = {  uilist{:},...
					{ } ...
					{ 'Style', 'pushbutton', 'string', 'Plot 2D', 'callback', plot2dcom },... 
					{ 'Style', 'text', 'string', 'Plot radius (0.2-1, []=auto)'} ...
					{ 'Style', 'edit', 'string', plotrad, 'tag', 'shrinkfactor' } ...
					{ 'Style', 'checkbox', 'tag', 'shrinkbut', 'string', 'Shrink to center', 'value', shrinkorskirt } ...
					{ 'Style', 'pushbutton', 'string', 'Plot 3D (XYZ)', 'callback', plot3d } ...
					{}, { 'Style', 'pushbutton', 'string', 'Read locations', 'callback', guireadlocs }, ...
					{ 'Style', 'pushbutton', 'string', 'Read help', 'callback', 'pophelp(''readlocs.m'');' }, ...	
					{ 'Style', 'pushbutton', 'string', 'Save .ced', 'callback', ...	
					  ['[tmpf tmpp] = uiputfile(''*.ced'', ''Save channel locs in EEGLAB .ced format''); drawnow;' ...
					   'comtmp = {''save'' [tmpp tmpf] }; clear tmpfmt tmpp tmpf;' endgui ] }, ...
					{ 'Style', 'pushbutton', 'string', 'Save others' 'callback', ...	
					  ['com = pop_writelocs(chantmp); comtmp = {''eval'' com }; clear tmpfmt tmpp tmpf;' endgui ] }, ...	
				 };
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -