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

📄 adjustlocs.m

📁 含有多种ICA算法的eeglab工具箱
💻 M
📖 第 1 页 / 共 2 页
字号:
                disp([ num2str(length(indelec)) ' landmark electrodes found for vertical spherical re-scaling' ]);                g.vscale(1:2:2*length(indelec))   = tmpnames1020 (indelec);                if strcmpi(g.coordinates, 'cart')                    g.vscale(2:2:2*length(indelec)+1) = cell2mat({ locs1020vert.X });                else                    g.vscale(2:2:2*length(indelec)+1) = tmpradius1020(indelec);                end;            end;            else            % uniform scaling            % ---------------            tmpnames      = lower(names);            tmpnames1020  = lower({ locs1020.labels });            tmpradius1020 = { locs1020.radius };            [tmp indelec] = intersect(tmpnames1020, tmpnames);                        if isempty(indelec)                disp('No electrodes found for uniform spherical re-scaling')            else                disp([ num2str(length(indelec)) ' landmark electrodes found for uniform spherical re-scaling' ]);                g.scale(1:2:2*length(indelec))   = tmpnames1020 (indelec);                if strcmpi(g.coordinates, 'cart')                    tmpabsxyz = mat2cell(abs(cell2mat({ locs1020.X })+j*cell2mat({ locs1020.Y })));                    g.scale(2:2:2*length(indelec)+1) = tmpabsxyz(indelec);                else                    g.scale(2:2:2*length(indelec)+1) = tmpradius1020(indelec);                end;            end;        end;        if strcmpi(g.coordinates, 'sph')            g.coordinates = 'pol'; % use polar coordinates for scaling        end;    end;        % get X and Y coordinates    % -----------------------    if strcmpi(g.coordinates, 'sph') | strcmpi(g.coordinates, 'pol')        [X Y] = pol2cart( cell2mat( { chanlocs.theta } )/180*pi, cell2mat( { chanlocs.radius })); Z = 1;        if strcmpi(g.coordinates, 'sph')            X = X/0.25*46;            Y = Y/0.25*46;        end;    else        X = cell2mat( { chanlocs.X } );        Y = cell2mat( { chanlocs.Y } );        Z = cell2mat( { chanlocs.Z } );    end;        % recenter    % --------    if ~isempty(g.center)        for index = 1:length(g.center)            tmpindex = strmatch( lower(g.center{index}), lower(names), 'exact' );            if isempty(tmpindex)                error(['Electrode ''' g.center{index} ''' not found for re-centering']);            end;            indexelec(index) = tmpindex;        end;        showmsg('Using electrode', 'for re-centering', g.center);        centerx = mean(X(indexelec));        centery = mean(Y(indexelec));        X = X - centerx;        Y = Y - centery;    end;    % planar rotation    % ---------------        if ~isempty(g.rotate)        % find electrodes        % ---------------        clear elec;        for index = 1:2:length(g.rotate)            tmpindex = strmatch( lower(g.rotate{index}), lower(names), 'exact' );            if isempty(tmpindex)                error(['Electrode ''' g.rotate{index} ''' not found for left-right scaling']);            end;            elec((index+1)/2) = tmpindex;        end;        vals = cell2mat(g.rotate(2:2:end));                % compute average scaling factor        % ------------------------------        [ allangles tmp ] = cart2pol(X(elec), Y(elec));        allangles = allangles/pi*180;        diffangle = allangles - vals;        %diffangle2 = allangles + vals;        %if abs(diffangle1) > abs(diffangle2), diffangle = diffangle2;        %else                                  diffangle = diffangle1;        %end;        tmpind    = find(diffangle >  180); diffangle(tmpind) = diffangle(tmpind)-360;        tmpind    = find(diffangle < -180); diffangle(tmpind) = diffangle(tmpind)+360;        anglerot  = mean(diffangle);        tmpcplx = (X+j*Y)*exp(-j*anglerot/180*pi);        X = real(tmpcplx);        Y = imag(tmpcplx);        showmsg('Using electrode', ['for planar rotation (' num2str(anglerot,2) ' degrees)'], g.rotate(1:2:end));    end;        % computing scaling factors    % -------------------------    if ~isempty(g.scale)        % find electrodes        % ---------------        clear elec;        for index = 1:2:length(g.scale)            tmpindex = strmatch( lower(g.scale{index}), lower(names), 'exact' );            if isempty(tmpindex)                error(['Electrode ''' g.scale{index} ''' not found for left-right scaling']);            end;            elec((index+1)/2) = tmpindex;        end;        vals = cell2mat(g.scale(2:2:end));                % compute average scaling factor        % ------------------------------        nonzero = find(vals > 0);        hscalefact = mean(abs(Y(elec(nonzero))+j*X(elec(nonzero)))./vals(nonzero)); % *46/0.25; %/44/0.25;        vscalefact = hscalefact;        showmsg('Using electrode', ['for uniform spherical re-scaling (x' num2str(1/hscalefact,4) ')'], g.scale(1:2:end));    else        if ~isempty(g.hscale)            % find electrodes            % ---------------            clear elec;            for index = 1:2:length(g.hscale)                tmpindex = strmatch( lower(g.hscale{index}), lower(names), 'exact' );                if isempty(tmpindex)                    error(['Electrode ''' g.hscale{index} ''' not found for left-right scaling']);                end;                elec((index+1)/2) = tmpindex;            end;            vals = cell2mat(g.hscale(2:2:end));            showmsg('Using electrode', [ 'for left-right spherical re-scaling (x' num2str(1/hscalefact,4) ')'], g.hscale(1:2:end));                        % compute average scaling factor            % ------------------------------            hscalefact = mean(abs(Y(elec))./vals); % *46/0.25; %/44/0.25;            if isempty(g.vscale)                vscalefact =  hscalefact;            end;        end;        if ~isempty(g.vscale)            % find electrodes            % ---------------            clear elec;            for index = 1:2:length(g.vscale)                tmpindex = strmatch( lower(g.vscale{index}), lower(names), 'exact' );                if isempty(tmpindex)                    error(['Electrode ''' g.vscale{index} ''' not found for rear-front scaling']);                end;                elec((index+1)/2) = tmpindex;            end;            vals = cell2mat(g.vscale(2:2:end));            showmsg('Using electrode', ['for rear-front spherical re-scaling (x' num2str(1/vscalefact,4) ')'], g.vscale(1:2:end));                        % compute average scaling factor            % ------------------------------            vscalefact = mean(abs(X(elec))./vals); % *46/0.25; %/44/0.25;            if isempty(g.vscale)                hscalefact =  vscalefact;            end;        end;    end;        % uniform?    % --------    if strcmpi(g.uniform, 'on') & ( ~isempty(g.vscale) | ~isempty(g.hscale))        disp('uniform scaling: averaging left-right and rear-front scaling factor');        hscalefact = mean([hscalefact vscalefact]);        vscalefact = hscalefact;    end;        % scaling data    % ------------    if ~isempty(g.vscale) | ~isempty(g.hscale) | ~isempty(g.scale)        Y = Y/hscalefact;        X = X/vscalefact;        Z = Z/((hscalefact+vscalefact)/2);    end;        % updating structure    % ------------------    if strcmpi(g.coordinates, 'sph') |  strcmpi(g.coordinates, 'pol')         [phi,theta] = cart2pol(Y, X);        phi = phi/pi*180;        if strcmpi(g.coordinates, 'pol')            theta = theta/0.25*46;        end;                % convert to other types of coordinates        % -------------------------------------        labels = names';        chanlocs = struct('labels', names, 'sph_theta_besa', mat2cell(theta), ...                'sph_phi_besa', mat2cell(phi), 'sph_radius', { chanlocs.sph_radius });        chanlocs = convertlocs( chanlocs, 'sphbesa2all');    else        for index = 1:length(chanlocs)            chanlocs(index).X = X(index);            chanlocs(index).Y = Y(index);            chanlocs(index).Z = Z(index);        end;        chanlocs = convertlocs(chanlocs, 'cart2all');    end;    function showmsg(begmsg, endmsg, struct);    if length(struct) <= 1        disp([ begmsg ' ''' struct{1} ''' ' endmsg]);    elseif length(struct) <= 2        disp([ begmsg ' ''' struct{1} ''' and ''' struct{2}  ''' ' endmsg]);    elseif length(struct) <= 3        disp([ begmsg ' ''' struct{1} ''', ''' struct{2} ''' and ''' struct{3}  ''' ' endmsg]);    else        disp([ begmsg ' ''' struct{1} ''', ''' struct{2} ''', ''' struct{3}  ''' ... ' endmsg]);    end;    

⌨️ 快捷键说明

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