topoimage.m
来自「含有多种ICA算法的eeglab工具箱」· M 代码 · 共 681 行 · 第 1/2 页
M
681 行
msg = [msg ' -> \n']; % print starting info on screen . . . fprintf(... '\nlimits: [xmin,xmax,ymin,ymax] = [%4.1f %4.1f %4.2f %4.2f]\n',... xmin,xmax,ymin,ymax); set(h,'YLim',[ymin ymax]); % set default plotting parameters set(h,'XLim',[xmin xmax]); set(h,'FontSize',FONTSIZE); % choose font size set(h,'FontSize',FONTSIZE); % choose font size set(h,'YLim',[ymin ymax]); % set default plotting parameters set(h,'XLim',[xmin xmax]); axis('off')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Read chan_locs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if size(loc_file,2) == 2 % plot in a rectangular grid ISRECT = 1; ht = loc_file(1); wd = loc_file(2); if chans > ht*wd fprintf(... '\ntopoimage(): (d%) channels to be plotted > grid size [%d %d]\n\n',... chans,ht,wd); return end hht = (ht-1)/2; hwd = (wd-1)/2; xvals = zeros(ht*wd,1); yvals = zeros(ht*wd,1); dist = zeros(ht*wd,1); for i=1:wd for j=1:ht xvals(i+(j-1)*wd) = -hwd+(i-1); yvals(i+(j-1)*wd) = hht-(j-1); dist(i+(j-1)*wd) = sqrt(xvals(j+(i-1)*ht).^2+yvals(j+(i-1)*ht).^2); end end maxdist = max(dist); for i=1:wd for j=1:ht xvals(i+(j-1)*wd) = 0.499*xvals(i+(j-1)*wd)/maxdist; yvals(i+(j-1)*wd) = 0.499*yvals(i+(j-1)*wd)/maxdist; end end channames = repmat(' ',ht*wd,4); for i=1:ht*wd channum = num2str(i); channames(i,1:length(channum)) = channum; end else % read chan_locs file fid = fopen(loc_file); if fid<1, fprintf('topoimage(): cannot open eloc_file "%s"\n',loc_file) return end A = fscanf(fid,'%d %f %f %s',[7 MAXCHANS]); fclose(fid); A = A'; if length(channels) > size(A,1), error('topoimage(): data channels must be <= chan_locs channels') end channames = setstr(A(channels,4:7)); idx = find(channames == '.'); % some labels have dots channames(idx) = setstr(abs(' ')*ones(size(idx))); % replace them with spaces Th = pi/180*A(channels,2); % convert degrees to rads Rd = A(channels,3); % ii = find(Rd <= 0.5); % interpolate on-head channels only % Th = Th(ii); % Rd = Rd(ii); [yvals,xvals] = pol2cart(Th,Rd);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%xvals = 0.5+PLOT_WIDTH*xvals; % controls width of plot array on page!yvals = 0.5+PLOT_HEIGHT*yvals; % controls height of plot array on page!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Plot traces %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% xdiff=xmax-xmin; rightmost = max(xvals); basetimes = find(x<=0);P=0; Axes = []; fprintf('\ntrace %d: ',P+1); for I=1:chans,%%%%%%%%%% for each data channel %%%%%%%%%%%%%%%%%%%%%%%%%% if P>0 axes(Axes(I)) hold on; % plot down left side of page first axis('off') else % P <= 0 % %%%%%%%%%%%%%%%%%%%%%%% Plot data images %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % xcenter = xvals(I); ycenter = yvals(I); Axes = [Axes axes('Units','Normal','Position', ... [xcenter-axwidth/2 ycenter-axheight/2 axwidth axheight])]; axes(Axes(I)) imageaxes = gca; axislcolor = get(gca,'Xcolor'); %%CJH dataimage = matsel(data,times,0,0,I); if rmbas~=0 % rm baseline dataimage = dataimage ... - repmat(mean(matsel(data,times,basetimes,0,I)')',1,times); end if exist('LOGIT') logimagesc(x,y,dataimage); % <---- plot logfreq image if exist('YVAL') YVAL = log(YVAL); end else imagesc(x,y,dataimage); % <---- plot image end hold on curax = axis; xtk = get(gca,'xtick'); % use these for cal axes below xtkl = get(gca,'xticklabel'); ytk = get(gca,'ytick'); ytkl = get(gca,'yticklabel'); set(gca,'tickdir','out'); set(gca,'ticklength',[0.02 0.05]); set(gca,'xticklabel',[]); set(gca,'yticklabel',[]); set(gca,'ydir','normal'); caxis([zmin zmax]); if exist('YVAL') & YVAL>=curax(3) & YVAL<=curax(4) hold on hp=plot([xmin xmax],[YVAL YVAL],'r-');%,'color',axislcolor); % draw horizontal axis set(hp,'Linewidth',1.0) end if xmin<0 & xmax>0 hold on vl= plot([0 0],[curax(3) curax(4)],'color',axislcolor); % draw vert axis set(vl,'linewidth',2); end % if xcenter == rightmost % colorbar % rightmost = Inf; % end % secondx = 200; % draw second vert axis % axis('off');plot([secondx secondx],[ymin ymax],'color',axislcolor); % %%%%%%%%%%%%%%%%%%%%%%% Print channel names %%%%%%%%%%%%%%%%%%%%%%%%%% % NAME_OFFSET = 0.01; if channels~=0, % print channames if ~ISRECT % print before topographically arrayed image % axis('off'); hold on h=text(xmin-NAME_OFFSET*xdiff,(curax(4)+curax(3))*0.5,[channames(I,:)]); set(h,'HorizontalAlignment','right'); set(h,'FontSize',CHANFONTSIZE); % choose font size else % print before rectangularly arrayed image if xmin<0 xmn = 0; else xmn = xmin; end % axis('off'); h=text(xmin-NAME_OFFSET*xdiff,ymax,[channames(I,:)]); set(h,'HorizontalAlignment','right'); set(h,'FontSize',TICKFONTSIZE); % choose font size end end; % channels end; % P=0 % if xcenter == rightmost % colorbar % rightmost = Inf; % end % if xmin<0 & xmax>0 % axes(imageaxes); % hold on; plot([0 0],[curax(3) curax(4)],'k','linewidth',2); % end drawnow fprintf(' %d',I); end; % %%%%%%%%%%%%%%% chan I %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fprintf('\n');%%%%%%%%%%%%%%%%%%%%%% Make time and freq cal axis %%%%%%%%%%%%%%%%%%%%%%%%%% ax = axes('Units','Normal','Position', ... [0.80 0.1 axwidth axheight]); axes(ax) axis('off'); imagesc(x,y,zeros(size(dataimage))); hold on % <---- plot green caxis([zmin zmax]); set(gca,'ydir','normal'); if xmin <=0 py=plot([0 0],[curax(3) curax(4)],'color','k'); % draw vert axis at time zero else py=plot([xmin xmin],[curax(3) curax(4)],'color','k'); % vert axis at xmin end hold on if exist('YVAL') & YVAL>=curax(3) px=plot([xmin xmax],[YVAL YVAL],'color',axislcolor); % draw horiz axis at YVAL else px=plot([xmin xmax],[curax(3) curax(4)],'color',axislcolor); % draw horiz axis at ymin end axis(curax); set(gca,'xtick',xtk); % use these for cal axes set(gca,'xticklabel',xtkl); set(gca,'ytick',ytk); set(gca,'yticklabel',ytkl); set(gca,'ticklength',[0.02 0.05]); set(gca,'tickdir','out'); h = colorbar; cbp = get(h,'position'); set(h,'position',[cbp(1) cbp(2) 2*cbp(3) cbp(4)]); caxis([zmin zmax]); % secondx = 200; % draw second vert axis % axis('off');plot([secondx secondx],[curax(3) curax(4)],'color',axislcolor); % %%%%%%%%%%%%%%%%%%%%% Plot axis values %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if 0 % DETOUR signx = xmin-0.15*xdiff; axis('off');h=text(signx,SIGN*curax(3),num2str(curax(3),3)); set(h,'FontSize',TICKFONTSIZE); % choose font size set(h,'HorizontalAlignment','right','Clipping','off'); textx = xmin-0.6*xdiff; axis('off');h=text(textx,(curax(3)+curax(4))/2,ylabel); % text Hz set(h,'Rotation',90); set(h,'FontSize',TICKFONTSIZE); % choose font size set(h,'HorizontalAlignment','center','Clipping','off'); % axis('off');h=text(signx,SIGN*ymax,['+' num2str(ymax,3)]); % text +ymax axis('off');h=text(signx,SIGN*ymax,[ num2str(ymax,3)]); % text ymax set(h,'FontSize',TICKFONTSIZE); % choose font size set(h,'HorizontalAlignment','right','Clipping','off'); ytick = curax(3)-0.3*(curax(4)-curax(3)); tick = [int2str(xmin)]; h=text(xmin,ytick,tick); % text xmin set(h,'FontSize',TICKFONTSIZE); % choose font size set(h,'HorizontalAlignment','center',... 'Clipping','off'); % center text h=text(xmin+xdiff/2,ytick-0.5*(curax(4)-curax(3)),xlabel);% text Times set(h,'FontSize',TICKFONTSIZE); % choose font size set(h,'HorizontalAlignment','center',... 'Clipping','off'); % center text tick = [int2str(xmax)]; h=text(xmax,ytick,tick); % text xmax set(h,'FontSize',TICKFONTSIZE); % choose font size set(h,'HorizontalAlignment','center',... 'Clipping','off'); % center text axis on set(ax,'xticklabel',''); set(ax,'yticklabel',''); set(ax,'ticklength',[0.02 0.05]); set(ax,'tickdir','out'); caxis([zmin zmax]); hc=colorbar; cmapsize = size(colormap,1); set(hc,'ytick',[1 cmapsize]); % minlabel = num2str(zmin,3); while (length(minlabel)<4) if ~contains(minlabel,'.') minlabel = [minlabel '.']; else minlabel = [minlabel '0']; end end maxlabel = num2str(zmax,3); if zmin<0 & zmax>0 maxlabel = ['+' maxlabel]; end while (length(maxlabel)<length(minlabel)) if ~contains(maxlabel,'.') maxlabel = [maxlabel '.']; else maxlabel = [maxlabel '0']; end end while (length(maxlabel)>length(minlabel)) if ~contains(minlabel,'.') minlabel = [minlabel '.']; else minlabel = [minlabel '0']; end end set(hc,'yticklabel',[minlabel;maxlabel]); set(hc,'Color',BACKCOLOR); set(hc,'Zcolor',BACKCOLOR); end % DETOURaxcopy(gcf); % turn on pop-up axes%%%%%%%%%%%%%%%%%%% Make printed figure fill page %%%%%%%%%%%%%%%%%%%%%%%%%%%% % orient tall % curfig = gcf; % h=figure(curfig); % set(h,'PaperPosition',[0.2 0.3 7.6 10]); % stretch out the plot on the pagefunction [returnval] = contains(strng,chr) returnval=0; for i=1:length(strng) if strng(i)==chr returnval=1; break end end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?