📄 plotdata.m
字号:
xmin = 0; xmax = frames-1; else dx = (xmax-xmin)/(frames-1); x=xmin*ones(1,frames)+dx*(0:frames-1); % compute x-values end; if xmax<=xmin, fprintf('plotdata() - xmax must be > xmin.\n') return end if ymax == 0 & ymin == 0, ymax=max(max(data)); ymin=min(min(data)); yrange = ymax-ymin; ymin = ymin - 0.00*yrange; ymax = ymax + 0.00*yrange; end if ymax<=ymin, fprintf('plotdata() - ymax must be > ymin.\n') return end xlabel = 'Time (ms)'; if ymin >= 0 & xmin >= 0, % For all-positive (spectral) data ISSPEC = 1; SIGN = 1; fprintf('\nPlotting positive up. Assuming data are spectra.\n'); xlabel = 'Freq (Hz)'; ymin = 0; % plot positive-up end;%%%%%%%%%%%%%%%%%%%%%%%%% Set up plotting environment %%%%%%%%%%%%%%%%%%%%%%%%%% h = gcf; % set(h,'YLim',[ymin ymax]); % set default plotting parameters % set(h,'XLim',[xmin xmax]); % set(h,'FontSize',18); % set(h,'DefaultLineLineWidth',1); % for thinner postscript lines%%%%%%%%%%%%%%%%%%%%%%%%%%% Print plot info %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clf; % clear the current figure % print plottitle over (left) subplot 1 if plottitle==0, plottitle = ''; end if righttitle==0, righttitle = ''; end subplot(ceil(chans/2),2,1), h=gca;%title([plottitle],'FontSize',FONTSIZE); % title plot and set(h,'YLim',[ymin ymax]); % set default plotting parameters set(h,'XLim',[xmin xmax]); set(h,'FontSize',FONTSIZE); % choose font size subplot(ceil(chans/2),2,2), h=gca;%title([righttitle], 'FontSize',FONTSIZE); % title plot and set(h,'FontSize',FONTSIZE); % choose font size set(h,'YLim',[ymin ymax]); % set default plotting parameters set(h,'XLim',[xmin xmax]); msg = ['\nPlotting %d traces of %d frames with colors: ']; for c=1:datasets msg = [msg colors(mod(c-1,length(colors))+1,:)]; end msg = [msg ' -> \n']; % print starting info on screen . . . fprintf(... '\n limits: [xmin,xmax,ymin,ymax] = [%4.1f %4.1f %4.2f %4.2f]\n',... xmin,xmax,ymin,ymax); fprintf(msg,datasets,frames);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Plot traces %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% xdiff=xmax-xmin; ydiff=ymax-ymin; for P=0:datasets-1, % for each data epoch fprintf('\ntrace %d: ',P+1); for I=1:chans, % for each data channel index=(2*((rem(I-1,ceil(chans/2))+1)))-1+floor(2*(I-1)/chans); subplot(ceil(chans/2),2,index); h=gca; % = 1 3 5 .. 2 4 6 .. hold on; % plot down left side of page first set(h,'YLim',[ymin ymax]); % set default plotting parameters set(h,'XLim',[xmin xmax]); axislcolor = get(gca,'Xcolor'); %%CJH % %%%%%%%%%%%%%%%%%%%%% Plot two-sided time-series data %%%%%%%%%%%%%%%%%%% % if ~ISSPEC ymin = min(data(I,1+P*frames:1+P*frames+frames-1)); ymax = max(data(I,1+P*frames:1+P*frames+frames-1)); if ymin == ymax, ymin = ymin-1; ymax = ymax+1; end; plot(x,SIGN*data(I,1+P*frames:1+P*frames+frames-1),colors(mod(P,length(colors))+1)); if SIGN > 0 axis([xmin xmax ymin ymax]); % set axis bounds (pos up) else axis([xmin xmax -1*ymax -1*ymin]); % set axis bounds (neg up) end if P==datasets-1, % on last traces if I==floor((chans+1)/2), % draw +/0 on lowest left plot signx = xmin-0.04*xdiff; if SIGN > 0 % pos up axis('off');hl=text(signx,ymin,num2str(ymin,3)); % text ymin axis('off');hi=text(signx,ymax,['+' num2str(ymax,3)]); % text +ymax else % neg up axis('off');hl=text(signx,-1*ymin,num2str(ymin,3)); % text ymin axis('off');hi=text(signx,-1*ymax,['+' num2str(ymax,3)]); % text +ymax end set(hl,'FontSize',TICKFONTSIZE); % choose font size set(hl,'HorizontalAlignment','right','Clipping','off'); set(hi,'FontSize',TICKFONTSIZE); % choose font size set(hi,'HorizontalAlignment','right','Clipping','off'); end if I==chans & limitset, % draw timescale on lowest right plot ytick = -ymax-0.25*ydiff; tick = [int2str(xmin)]; h=text(xmin,ytick,tick); set(h,'FontSize',TICKFONTSIZE); % choose font size set(h,'HorizontalAlignment','center',... 'Clipping','off'); % center text tick = [xlabel]; h=text(xmin+xdiff/2,ytick,tick); set(h,'FontSize',TICKFONTSIZE); % choose font size set(h,'HorizontalAlignment','center',... 'Clipping','off'); % center text tick = [int2str(xmax)]; h=text(xmax,ytick,tick); set(h,'FontSize',TICKFONTSIZE); % choose font size set(h,'HorizontalAlignment','center',... 'Clipping','off'); % center text end; end; % %%%%%%%%%%%%%%%%%%%%% Plot positive-up [0,ymax] %%%%%%%%%%%%%%%%%%%%%%%% % else % ISSPEC ymin=0; plot(x,SIGN*data(I,1+P*frames:1+P*frames+frames-1),colors(mod(P,length(colors))+1)); ymaxm = ymax; % ymin = 0.01; % ymaxm = 10.^ceil(log(ymax)/log(10.)); % if ymaxm/2. > ymax, % ymaxm = ymaxm/2.; % end; axis([xmin xmax ymin ymaxm]); % set axis values if P==datasets-1, % on last trace if I==floor((chans+1)/2), % draw +/0 on lowest left plot signx = xmin-0.04*xdiff; axis('off');h=text(signx,ymax,['+' num2str(ymax,3)]); set(h,'FontSize',TICKFONTSIZE); set(h,'HorizontalAlignment','right','Clipping','off'); axis('off');h=text(signx,0,'0'); set(h,'FontSize',TICKFONTSIZE); set(h,'HorizontalAlignment','right','Clipping','off'); end; if I==chans, % draw freq scale on lowest right plot ytick = -0.25*ymax; tick = [num2str(round(10*xmin)/10) ]; h=text(xmin,ytick,tick); set(h,'FontSize',TICKFONTSIZE); set(h,'HorizontalAlignment','center','Clipping','off'); tick = [xlabel]; h=text(xmin+xdiff/2,ytick,tick); set(h,'FontSize',TICKFONTSIZE); set(h,'HorizontalAlignment','center','Clipping','off'); tick = [num2str(round(10*xmax)/10) ]; h=text(xmax,ytick,tick); set(h,'FontSize',TICKFONTSIZE); set(h,'HorizontalAlignment','center','Clipping','off'); end; % if last chan end % if last data end; % if ~ISSPEC %%%%%%%%%%%%%%%%%%%%%%% Print channel names and lines %%%%%%%%%%%%%%%%%%%%%%%%%% if P==datasets-1 if ~ISSPEC axis('off'); plot([0 0],[ymin ymax],'color',axislcolor); % draw vert %%CJH % axis at time 0 else % ISSPEC axis('off');plot([xmin xmin],[0 ymax],'color',axislcolor); end % secondx = 200; % draw second vert axis % axis('off');plot([secondx secondx],[ymin ymax],'color',axislcolor); axis('off'); plot([xmin xmax],[0 0],'color',axislcolor); % draw horizontal axis if ~isempty(channels), % print channames if ~ISSPEC if ymin <= 0 & ymax >= 0, yht = 0; else yht = nan_mean(SIGN*data(I,1+P*frames:1+P*frames+frames-1)); end axis('off'),h=text(xmin-0.04*xdiff,yht,[channames(I,:)]); set(h,'HorizontalAlignment','right'); % print before traces set(h,'FontSize',FONTSIZE); % choose font size % axis('off'),h=text(xmax+0.10*xdiff,yht,[channames(I,:)]); % set(h,'HorizontalAlignment','left'); % print after traces else % ISSPEC axis('off'),h=text(xmin-0.04*xdiff,ymax/2,[channames(I,:)]); set(h,'HorizontalAlignment','right'); % print before traces set(h,'FontSize',FONTSIZE); % choose font size % axis('off'),h=text(xmax+0.10*xdiff,ymax/2,[channames(I,:)]); % set(h,'HorizontalAlignment','left'); % print after traces end; end; end; fprintf(' %d',I); end; % subplot end; % dataset fprintf('\n');%%%%%%%%%%%%%%%%%%% Make printed figure fill page %%%%%%%%%%%%%%%%%%%%%%%%%%%% curfig = gcf; h=figure(curfig); % set(h,'PaperPosition',[0.2 0.3 7.6 10]); % stretch out the plot on the page%%%%%%%%%%%%%%%%%%% Restore plot environment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % set(h,'DefaultAxesYLim',aylim); % restore previous plotting parameters % set(h,'DefaultAxesXLim',axlim); % set(h,'DefaultAxesFontSize',axfont);%%%%%%%%%%%%%%%%%% Add axcopy %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if plottitle h = textsc(plottitle, 'title'); set(h, 'fontsize', FONTSIZE);end;axcopy(gcf, 'axis on');if 0, % START DETOUR XXXXXXXXXXXXX%%%%%%%%%%%%%%%%%%% Save plot to disk if asked %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if plotfile ~= '', % n=0; y=1; answer = input('plotdata: Save plot as Postscript file? (y/n) '); if answer==1, fprintf('\nSaving figure as %s ... ',plotfile); curfig = gcf; h=figure(curfig); % set(h,'PaperPosition',[0.2 0.3 7.6 10]); % stretch out the plot on the page eval (['print -dpsc ' plotfile]); fprintf('saved. Move or remove file!\n'); unix(ls_plotfile); end endend % END DETOUR XXXXXXXXXXXXXfunction out = nan_mean(in) nans = find(isnan(in)); in(nans) = 0; sums = sum(in); nonnans = ones(size(in)); nonnans(nans) = 0; nonnans = sum(nonnans); nononnans = find(nonnans==0); nonnans(nononnans) = 1; out = sum(in)./nonnans; out(nononnans) = NaN;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -