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

📄 pop_dipfit_manual.m

📁 含有多种ICA算法的eeglab工具箱
💻 M
📖 第 1 页 / 共 2 页
字号:
              { 'style' 'text'        'string' '#2' 'tag' 'dip2'                                 } ...              { 'style' 'checkbox'    'string' ''   'tag' 'dip2act'    'callback' cb_checkinput  } { } ...              { 'style' 'checkbox'    'string' ''   'tag' 'dip2sel'    'callback' cb_checkinput  } { } ...              { 'style' 'edit'        'string' ''   'tag' 'dip2pos'    'callback' cb_checkinput  } ...              { 'style' 'edit'        'string' ''   'tag' 'dip2mom'    'callback' cb_checkinput  } ...              { 'style' 'pushbutton'  'string' 'Flip (in|out)'         'callback' cb_flip2       } ...                 ...              { } { 'style' 'checkbox' 'string' 'Symmetry constrain for dipole #2' 'tag' 'dip2sym' 'callback' cb_checkinput  'value' 1 } ...              { } { } { } ...              { 'style' 'pushbutton'  'string' 'Fit selected dipole position(s)' 'callback' cb_fitposition } ...                 { 'style' 'pushbutton'  'string' 'Fit selected dipole moment(s)'   'callback' cb_fitmoment   } ...                 { 'style' 'pushbutton'  'string' 'Plot dipole(s)'                  'callback' cb_plotdip     } ...   	    };% add the cancel, help and ok buttons at the bottomgeomvert  = [geomvert 1 1];geomhoriz = {geomhoriz{:} [1] [1 1 1]};elements  = { elements{:} ...              { } ...              { 'Style', 'pushbutton', 'string', 'Cancel', 'callback', cb_close } ...              { 'Style', 'pushbutton', 'string', 'Help',   'callback', cb_help  } ...              { 'Style', 'pushbutton', 'string', 'OK',     'callback', cb_ok    } ...            };% activate the graphical interfacesupergui(0, geomhoriz, geomvert, elements{:});dlg = gcf;set(gcf, 'name', 'Manual dipole fit -- pop_dipfit_manual()');set(gcf, 'userdata', EEG);pop_dipfit_manual(EEG, 'dialog_setvalue', dlg);uiwait(dlg);if ishandle(dlg)  pop_dipfit_manual(EEG, 'dialog_getvalue', dlg);  % FIXME, rv is undefined since the user may have changed dipole parameters  % FIXME, see also dialog_getvalue subfucntion  OUTEEG = get(dlg, 'userdata');  close(dlg);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% implement all subfunctions through a switch-yard%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%elseif nargin>=3  %disp(subfunction)  EEG = get(parent, 'userdata');  switch subfunction  case 'dialog_selectcomponent'    current = get(findobj(parent, 'tag', 'component'), 'string');    current = str2num(current);    current = current(1);    current = min(current, size(EEG.icaweights,1));    current = max(current, 1);    set(findobj(parent, 'tag', 'component'), 'string', int2str(current));    EEG.dipfit.current = current;    % reassign the global EEG object back to the dialogs userdata    set(parent, 'userdata', EEG);    % redraw the dialog with the current model    pop_dipfit_manual(EEG, 'dialog_setvalue', parent);       case 'dialog_plotmap'    current = str2num(get(findobj(parent, 'tag', 'component'), 'string'));    figure; topoplot(EEG.icawinv(:,current), EEG.chanlocs);     title([ 'IC ' int2str(current) ]);   case 'dialog_plotcomponent'    current = get(findobj(parent, 'tag', 'component'), 'string');    EEG.dipfit.current = str2num(current);    if ~isempty( EEG.dipfit.current )        pop_dipplot(EEG, 'DIPFIT',  EEG.dipfit.current, 'normlen', 'on', 'image', 'mri');    end;       case 'dialog_checkinput'    if get(findobj(parent, 'tag', 'dip1sel'), 'value') & ~get(findobj(parent, 'tag', 'dip1act'), 'value')        set(findobj(parent, 'tag', 'dip1act'), 'value', 1);    end    if get(findobj(parent, 'tag', 'dip2sel'), 'value') & ~get(findobj(parent, 'tag', 'dip2act'), 'value')        set(findobj(parent, 'tag', 'dip2act'), 'value', 1);    end    if ~all(size(str2num(get(findobj(parent, 'tag', 'dip1pos'), 'string')))==[1 3])        set(findobj(parent, 'tag', 'dip1pos'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).posxyz(1,:)));    else        EEG.dipfit.model(EEG.dipfit.current).posxyz(1,:) = str2num(get(findobj(parent, 'tag', 'dip1pos'), 'string'));    end    if ~all(size(str2num(get(findobj(parent, 'tag', 'dip2pos'), 'string')))==[1 3])        set(findobj(parent, 'tag', 'dip2pos'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).posxyz(2,:)));    else        EEG.dipfit.model(EEG.dipfit.current).posxyz(2,:) = str2num(get(findobj(parent, 'tag', 'dip2pos'), 'string'));    end    if ~all(size(str2num(get(findobj(parent, 'tag', 'dip1mom'), 'string')))==[1 3])        set(findobj(parent, 'tag', 'dip1mom'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).momxyz(1,:)));    else        EEG.dipfit.model(EEG.dipfit.current).momxyz(1,:) = str2num(get(findobj(parent, 'tag', 'dip1mom'), 'string'));    end    if ~all(size(str2num(get(findobj(parent, 'tag', 'dip2mom'), 'string')))==[1 3])        set(findobj(parent, 'tag', 'dip2mom'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).momxyz(2,:)));    else        EEG.dipfit.model(EEG.dipfit.current).momxyz(2,:) = str2num(get(findobj(parent, 'tag', 'dip2mom'), 'string'));    end    if get(findobj(parent, 'tag', 'dip2sel'), 'value') & get(findobj(parent, 'tag', 'dip2sym'), 'value') & ~get(findobj(parent, 'tag', 'dip1sel'), 'value')        set(findobj(parent, 'tag', 'dip2sel'), 'value', 0);    end    set(parent, 'userdata', EEG);  case 'dialog_setvalue'    % synchronize the gui with the data    set(findobj(parent, 'tag', 'component'), 'string', EEG.dipfit.current);    set(findobj(parent, 'tag', 'relvar' ), 'string', sprintf('%0.2f%%', EEG.dipfit.model(EEG.dipfit.current).rv * 100));    set(findobj(parent, 'tag', 'dip1act'), 'value', ismember(1, EEG.dipfit.model(EEG.dipfit.current).active));    set(findobj(parent, 'tag', 'dip2act'), 'value', ismember(2, EEG.dipfit.model(EEG.dipfit.current).active));    set(findobj(parent, 'tag', 'dip1sel'), 'value', ismember(1, EEG.dipfit.model(EEG.dipfit.current).select));    set(findobj(parent, 'tag', 'dip2sel'), 'value', ismember(2, EEG.dipfit.model(EEG.dipfit.current).select));    set(findobj(parent, 'tag', 'dip1pos'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).posxyz(1,:)));    set(findobj(parent, 'tag', 'dip2pos'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).posxyz(2,:)));    set(findobj(parent, 'tag', 'dip1mom'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).momxyz(1,:)));    set(findobj(parent, 'tag', 'dip2mom'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).momxyz(2,:)));  case 'dialog_getvalue'    % synchronize the data with the gui    if get(findobj(parent, 'tag', 'dip1act'), 'value'); active = [1]; else active = []; end;     if get(findobj(parent, 'tag', 'dip2act'), 'value'); active = [active 2]; end;     if get(findobj(parent, 'tag', 'dip1sel'), 'value'); select = [1]; else select = []; end;     if get(findobj(parent, 'tag', 'dip2sel'), 'value'); select = [select 2]; end;     posxyz(1,:) = str2num(get(findobj(parent, 'tag', 'dip1pos'), 'string'));     posxyz(2,:) = str2num(get(findobj(parent, 'tag', 'dip2pos'), 'string'));     momxyz(1,:) = str2num(get(findobj(parent, 'tag', 'dip1mom'), 'string'));     momxyz(2,:) = str2num(get(findobj(parent, 'tag', 'dip2mom'), 'string'));     % assign the local values to the global EEG object    EEG.dipfit.model(EEG.dipfit.current).posxyz = posxyz;    EEG.dipfit.model(EEG.dipfit.current).momxyz = momxyz;    EEG.dipfit.model(EEG.dipfit.current).active = active;    EEG.dipfit.model(EEG.dipfit.current).select = select;    % FIXME, rv is undefined after a manual change of parameters    % FIXME, this should either be undated continuously or upon OK buttonpress    % EEG.dipfit.model(EEG.dipfit.current).rv = nan;    % reassign the global EEG object back to the dialogs userdata    set(parent, 'userdata', EEG);  case 'dialog_flip'    % make a copy of the electrodes, with only the selected ones    current = EEG.dipfit.current;    moment  = EEG.dipfit.model(current).momxyz;    EEG.dipfit.model(current).momxyz(dipnum,:) = [ -moment(dipnum,1) -moment(dipnum,2) -moment(dipnum,3)];    set(findobj(parent, 'tag', ['dip' int2str(dipnum) 'mom']), 'string', ...                      sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).momxyz(dipnum,:)));    set(parent, 'userdata', EEG);     case 'dipfit_position'    % make a copy of the electrodes and get the selected channels    elc     = getelecpos(EEG.chanlocs, EEG.dipfit);    chansel = EEG.dipfit.chansel;    elc     = elc(chansel,:);    % make some other local copies for convenience    current = EEG.dipfit.current;    model   = EEG.dipfit.model(current);    pot     = EEG.icawinv(chansel,current);    vol     = EEG.dipfit.vol;    if isempty(model.select)      % no dipoles are selected, nothing to do      return;    end    % set the symmetry constraint for dipole 2    dipfitdefs;    if get(findobj(parent, 'tag', 'dip2sym'), 'value') & get(findobj(parent, 'tag', 'dip2sel'), 'value')      constr = defaultconstraint;    else      constr = [];    end    % make a dialog which can interrupt the fitting procedure    fig = figure('visible', 'off');    supergui( fig, {1 1}, [], ...        {'style' 'text' 'string' 'Press button below to stop fitting' }, ...        {'style' 'pushbutton' 'string' 'Interupt' 'callback' 'figure(gcbf); set(gcbf, ''tag'', ''stop'');' } );    drawnow;    model = dipfit_manual(model, pot, elc, vol, 'method', 'position', 'constraint', constr );    % remember the fitted dipole object    EEG.dipfit.model(current) = model;    % reassign the global EEG object back to the dialogs userdata    set(parent, 'userdata', EEG);    if ishandle(fig)      close(fig);    end  case 'dipfit_moment'    % make a copy of the electrodes, with only the selected ones    elc     = getelecpos(EEG.chanlocs, EEG.dipfit);    chansel = EEG.dipfit.chansel;    elc     = elc(chansel,:);    % make some other local copies for convenience    current = EEG.dipfit.current;    model   = EEG.dipfit.model(current);    pot     = EEG.icawinv(chansel,current);    vol     = EEG.dipfit.vol;    if isempty(model.select)      % no dipoles are selected, nothing to do      return;    end    model = dipfit_manual(model, pot, elc, vol, 'method', 'moment' );    % remember the fitted dipole object    EEG.dipfit.model(current) = model;    % reassign the global EEG object back to the dialogs userdata    set(parent, 'userdata', EEG);  otherwise    error('unknown subfunction for pop_dipfit_manual');  end		% switch subfunctionend		% if nargin% get electrode positions from eeglag% -----------------------------------function elc = getelecpos(chanlocs, dipfitstruct);    try,        elc = cell2mat({chanlocs.X; chanlocs.Y; chanlocs.Z}');    catch        disp('No 3-D carthesian coordinates; re-computing them from 2-D polar coordinates');        EEG.chanlocs = convertlocs(EEG.chanlocs, 'topo2all');        elc = cell2mat({chanlocs.X; chanlocs.Y; chanlocs.Z}');    end;    % constrain electrode to sphere    % -----------------------------    disp('Constraining electrodes to sphere');    elc = elc - repmat( dipfitstruct.vol.o, [size(elc,1) 1]); % recenter     % (note the step above is not needed since the origin should always be 0)    elc = elc ./ repmat( sqrt(sum(elc.*elc,2)), [1 3]); % normalize    elc = elc * max(dipfitstruct.vol.r);         % head size        %for index= 1:size(elc,1)    %    elc(index,:) = max(dipfitstruct.vol.r) * elc(index,:) /norm(elc(index,:));    %end;

⌨️ 快捷键说明

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