Home > FMAToolbox > Analyses > SyncMap.m

SyncMap

PURPOSE ^

SyncMap - Create a map from successive event-synchronized data.

SYNOPSIS ^

function [map,timeBins] = SyncMap(synchronized,indices,varargin)

DESCRIPTION ^

SyncMap - Create a map from successive event-synchronized data.

 Using N repetitions of similar data centered around synchronizing
 events (e.g. N evoked potentials), create a map v = f(t,i) where
 t is the time relative to the synchronizing events and i is the
 occurrence (from 1 to N).

  USAGE

    [map,timeBins] = SyncMap(synchronized,indices,<options>)

    synchronized   event-synchronized <a href="matlab:help samples">samples</a>
    indices        list of synchronizing event indices for each sample
    <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])
     'nBins'       total number of time bins (default 100)
     'smooth'      smoothing size (0 = no smoothing) (default = 0.01*nBins)
    =========================================================================

  SEE

    See also Sync, SyncHist, PlotSync, PETHTransition.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [map,timeBins] = SyncMap(synchronized,indices,varargin)
0002 
0003 %SyncMap - Create a map from successive event-synchronized data.
0004 %
0005 % Using N repetitions of similar data centered around synchronizing
0006 % events (e.g. N evoked potentials), create a map v = f(t,i) where
0007 % t is the time relative to the synchronizing events and i is the
0008 % occurrence (from 1 to N).
0009 %
0010 %  USAGE
0011 %
0012 %    [map,timeBins] = SyncMap(synchronized,indices,<options>)
0013 %
0014 %    synchronized   event-synchronized <a href="matlab:help samples">samples</a>
0015 %    indices        list of synchronizing event indices for each sample
0016 %    <options>      optional list of property-value pairs (see table below)
0017 %
0018 %    =========================================================================
0019 %     Properties    Values
0020 %    -------------------------------------------------------------------------
0021 %     'durations'   durations before and after synchronizing events for each
0022 %                   trial (in s) (default = [-0.5 0.5])
0023 %     'nBins'       total number of time bins (default 100)
0024 %     'smooth'      smoothing size (0 = no smoothing) (default = 0.01*nBins)
0025 %    =========================================================================
0026 %
0027 %  SEE
0028 %
0029 %    See also Sync, SyncHist, PlotSync, PETHTransition.
0030 
0031 % Copyright (C) 2004-2011 by Michaël Zugaro
0032 %
0033 % This program is free software; you can redistribute it and/or modify
0034 % it under the terms of the GNU General Public License as published by
0035 % the Free Software Foundation; either version 3 of the License, or
0036 % (at your option) any later version.
0037 
0038 % Default values
0039 durations = [-0.5 0.5];
0040 nBins = 100;
0041 smooth = [];
0042 
0043 % Check number of parameters
0044 if nargin < 2 | mod(length(varargin),2) ~= 0,
0045   error('Incorrect number of parameters (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0046 end
0047 
0048 % Check parameter sizes
0049 if size(synchronized,2) > 2,
0050     error('Parameter ''synchronized'' is not a Nx2 matrix (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0051 end
0052 if size(indices,2) ~= 1,
0053     error('Parameter ''indices'' is not a vector (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0054 end
0055 if size(indices,1) ~= size(synchronized,1),
0056     error('Parameters ''synchronized'' and ''indices'' have different lengths (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0057 end
0058 
0059 % Parse parameter list
0060 for i = 1:2:length(varargin),
0061     if ~ischar(varargin{i}),
0062         error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).']);
0063     end
0064     switch(lower(varargin{i})),
0065         case 'durations',
0066             durations = varargin{i+1};
0067             if ~isdvector(durations,'#2','<'),
0068                 error('Incorrect value for property ''durations'' (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0069             end
0070         case 'nbins',
0071             nBins = varargin{i+1};
0072             if ~isiscalar(nBins,'>0'),
0073                 error('Incorrect value for property ''nBins'' (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0074             end
0075         case 'smooth',
0076             smooth = varargin{i+1};
0077             if ~isdvector(smooth,'>=0'),
0078                 error('Incorrect value for property ''smooth'' (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).');
0079             end
0080 
0081         otherwise,
0082             error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help SyncMap">SyncMap</a>'' for details).']);
0083     end
0084 end
0085 
0086 
0087 if isempty(smooth),
0088     smooth = ceil(0.01*nBins);
0089 end
0090 
0091 start = durations(1);
0092 stop = durations(2);
0093 timeBinSize = (stop - start)/nBins;
0094 timeBins = (start:timeBinSize:stop-timeBinSize)+timeBinSize/2;
0095 binnedTime = Bin(synchronized(:,1),durations,nBins);
0096 if size(synchronized,2) == 1,
0097     % Occurrences
0098     s = Accumulate([indices binnedTime],1);
0099     map = Smooth(s,smooth);
0100 else
0101     % Values
0102     s = Accumulate([indices binnedTime],synchronized(:,2));
0103     n = Accumulate([indices binnedTime],1);
0104     n(n==0) = 1;
0105     map = Smooth(s,[smooth 0])./Smooth(n,[smooth 0]);
0106 end

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