0001 function PlotSync(synchronized,indices,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
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
0050 durations = [-0.5 0.5];
0051 if size(synchronized,2) == 1,
0052
0053 pointProcess = true;
0054 spacing = 1;
0055 synchronized(:,2) = 1;
0056 else
0057
0058 pointProcess = false;
0059 spacing = 0;
0060 end
0061
0062
0063
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
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
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
0106 set(gca,'XLim',durations,'YLim',[minY maxY]);
0107 line([0 0],ylim,'linestyle','--','color',[0 0 0]);