Home > FMAToolbox > Plot > PlotSync.m

PlotSync

PURPOSE ^

PlotSync - Plot successive occurrences of a multidimensional variable.

SYNOPSIS ^

function PlotSync(synchronized,indices,varargin)

DESCRIPTION ^

PlotSync - Plot successive occurrences of a multidimensional variable.

 Plot resynchronized samples such as spike rasters or successive evoked
 potentials.

  USAGE

    PlotSync(synchronized,indices,<options>)

    synchronized   synchronized <a href="matlab:help samples">samples</a> (obtained using <a href="matlab:help Sync">Sync</a>)
    indices        synchronizing event indices (obtained using <a href="matlab:help Sync">Sync</a>)
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'durations'   durations before and after synchronizing events for each
                   trial (in s) (default = [-0.5 0.5])
     'spacing'     vertical spacing between samples occurring around
                   successive synchronizing events (default = 1 for point
                   processes, 0 for continuous data)
    =========================================================================

  SEE

    See also Sync, SyncHist, SyncMap.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function PlotSync(synchronized,indices,varargin)
0002 
0003 %PlotSync - Plot successive occurrences of a multidimensional variable.
0004 %
0005 % Plot resynchronized samples such as spike rasters or successive evoked
0006 % potentials.
0007 %
0008 %  USAGE
0009 %
0010 %    PlotSync(synchronized,indices,<options>)
0011 %
0012 %    synchronized   synchronized <a href="matlab:help samples">samples</a> (obtained using <a href="matlab:help Sync">Sync</a>)
0013 %    indices        synchronizing event indices (obtained using <a href="matlab:help Sync">Sync</a>)
0014 %    <options>      optional list of property-value pairs (see table below)
0015 %
0016 %    =========================================================================
0017 %     Properties    Values
0018 %    -------------------------------------------------------------------------
0019 %     'durations'   durations before and after synchronizing events for each
0020 %                   trial (in s) (default = [-0.5 0.5])
0021 %     'spacing'     vertical spacing between samples occurring around
0022 %                   successive synchronizing events (default = 1 for point
0023 %                   processes, 0 for continuous data)
0024 %    =========================================================================
0025 %
0026 %  SEE
0027 %
0028 %    See also Sync, SyncHist, SyncMap.
0029 
0030 % Copyright (C) 2004-2011 by Michaƫl Zugaro
0031 %
0032 % This program is free software; you can redistribute it and/or modify
0033 % it under the terms of the GNU General Public License as published by
0034 % the Free Software Foundation; either version 3 of the License, or
0035 % (at your option) any later version.
0036 
0037 % Check arguments
0038 if nargin < 2 | mod(length(varargin),2) ~= 0,
0039 error('Incorrect number of parameters (type ''help <a href="matlab:help PlotSync">PlotSync</a>'' for details).');
0040 end
0041 if isempty(indices) || isempty(synchronized), return; end
0042 if min(size(indices)) ~= 1,
0043     error('''indices'' is not a vector (type ''help <a href="matlab:help PlotSync">PlotSync</a>'' for details).');
0044 end
0045 if length(synchronized) ~= length(indices),
0046     error('''synchronized'' and ''indices'' have different lengths (type ''help <a href="matlab:help PlotSync">PlotSync</a>'' for details).');
0047 end
0048 
0049 % Default values
0050 durations = [-0.5 0.5];
0051 if size(synchronized,2) == 1,
0052     % Point process data
0053     pointProcess = true;
0054     spacing = 1;
0055     synchronized(:,2) = 1;
0056 else
0057     % Continuous-valued data
0058     pointProcess = false;
0059     spacing = 0;
0060 end
0061 
0062 
0063 % Parse parameter list
0064 for i = 1:2:length(varargin),
0065     if ~ischar(varargin{i}),
0066         error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help PlotSync">PlotSync</a>'' for details).']);
0067     end
0068     switch(lower(varargin{i})),
0069         case 'durations',
0070             durations = varargin{i+1};
0071             if ~isdvector(durations,'#2','<'),
0072                 error('Incorrect value for property ''durations'' (type ''help <a href="matlab:help PlotSync">PlotSync</a>'' for details).');
0073             end
0074 
0075         case 'spacing',
0076             spacing = varargin{i+1};
0077             if ~isdscalar(spacing),
0078                 error('Incorrect value for property ''spacing'' (type ''help <a href="matlab:help PlotSync">PlotSync</a>'' for details).');
0079             end
0080 
0081         otherwise,
0082             error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help PlotSync">PlotSync</a>'' for details).']);
0083     end
0084 end
0085 
0086 % Plot
0087 hold on;
0088 if pointProcess,
0089     PlotTicks(synchronized(:,1),(indices-1)*spacing);
0090 else
0091     nSync = max(indices);
0092     for i = 1:nSync,
0093         trial = indices==i;
0094         p = plot(synchronized(trial,1),(i-1)*spacing+synchronized(trial,2));
0095     end
0096 end
0097 % Determine axes limits
0098 minY = min(synchronized(:,2)+spacing*(indices-1));
0099 maxY = max(synchronized(:,2)+spacing*(indices-1));
0100 if minY == maxY, minY = minY-eps; end
0101 if min(synchronized(:,1)) < durations(1) | max(synchronized(:,1)) > durations(2),
0102     warning(['Some data points do not fall within [' num2str(durations(1)) ';' num2str(durations(2)) ']']);
0103 end
0104 
0105 % Update axes
0106 set(gca,'XLim',durations,'YLim',[minY maxY]);
0107 line([0 0],ylim,'linestyle','--','color',[0 0 0]);

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005