Home > chronux > spectral_analysis > plots > plot_vector.m

plot_vector

PURPOSE ^

Function to plot a frequency dependent vector X. If error bars are specified in Xerr,

SYNOPSIS ^

function plot_vector(X,f,plt,Xerr,c,w)

DESCRIPTION ^

 Function to plot a frequency dependent vector X. If error bars are specified in Xerr,
 it also plots them. Xerr can either contain upper and lower confidence intervals 
 on X, or simply a theoretical confidence level (for the coherence). Used
 to plot the spectrum and coherency.
 Usage: plot_vector(X,f,plt,Xerr,c)
 Inputs:
 X: input vector as a function of frequency (f), see third argument
 f: f axis grid for plot. Default. [1:length(X)]
 plt: 'l' for log, 'n' for no log.
 Xerr: lower and upper confidence intervals for X1: lower/upper x f. Or
       simply a single number specifying an f-independent confidence
       level.
 c: controls the color of the plot - input 'b','g','r' etc. Default 'b'
 w: controls the width of the lines - input 1, 1.5, 2 etc

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function plot_vector(X,f,plt,Xerr,c,w)
0002 % Function to plot a frequency dependent vector X. If error bars are specified in Xerr,
0003 % it also plots them. Xerr can either contain upper and lower confidence intervals
0004 % on X, or simply a theoretical confidence level (for the coherence). Used
0005 % to plot the spectrum and coherency.
0006 % Usage: plot_vector(X,f,plt,Xerr,c)
0007 % Inputs:
0008 % X: input vector as a function of frequency (f), see third argument
0009 % f: f axis grid for plot. Default. [1:length(X)]
0010 % plt: 'l' for log, 'n' for no log.
0011 % Xerr: lower and upper confidence intervals for X1: lower/upper x f. Or
0012 %       simply a single number specifying an f-independent confidence
0013 %       level.
0014 % c: controls the color of the plot - input 'b','g','r' etc. Default 'b'
0015 % w: controls the width of the lines - input 1, 1.5, 2 etc
0016 
0017 if nargin < 1; error('Need data'); end;
0018 N=length(X); 
0019 if nargin < 2 || isempty(f);
0020     f=1:N;
0021 end;
0022 if length(f)~=N; error('frequencies and data have incompatible lengths'); end;
0023 if nargin < 3 || isempty(plt) ;
0024     plt='l';
0025 end;
0026 if nargin < 4 || isempty(Xerr);
0027     Xerr=[];
0028 end;
0029 if nargin < 5 || isempty(c)
0030     c='b';
0031 end;
0032 if nargin < 6 || isempty(w);
0033     w=1;
0034 end;
0035 
0036 if strcmp(plt,'l');
0037     X=10*log10(X);
0038     if nargin >=4 & ~isempty(Xerr); Xerr=10*log10(Xerr); end;
0039 end;
0040 
0041 if nargin < 4 || isempty(Xerr);
0042     plot(f,X,c,'Linewidth',w);
0043 else
0044     if length(Xerr)==1;
0045        plot(f,X,c); 
0046        line(get(gca,'xlim'),[Xerr,Xerr],'Color',c,'LineStyle','--','Linewidth',w);
0047     elseif ~isempty(Xerr);
0048        plot(f,X,c); 
0049        hold on; plot(f,Xerr(1,:),[c '--'],'Linewidth',w); plot(f,Xerr(2,:),[c '--'],'Linewidth',w); 
0050     end
0051 end
0052 xlabel('f');
0053 if strcmp(plt,'l'); ylabel('10*log10(X)'); else ylabel('X'); end;
0054 
0055

Generated on Fri 28-Sep-2012 12:34:30 by m2html © 2005