-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsp_plot.m
55 lines (51 loc) · 1.65 KB
/
sp_plot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function sp_plot(varargin)
% function sp_plot(varargin)
%
% A simple replacement for plot() in cases where multiple vectors with the same number of samples need to be overlayed.
% The data is plotted with the following color ordering: {'r','g','b','c','m','y','k'}
%
% INPUTS:
% varargin: [arrays] with data in them. All arrays must have the same length
%
% Sagi Perel, 03/2011
if(nargin == 0)
return;
end
% check that all inputs have the same length
options = {};
nargin_to_plot = nargin;
len = length(varargin{1});
for i=2:nargin
if(isscalar(varargin{i}) && isvector(varargin{i}))
if(length(varargin{i}) ~= len)
error('sp_plot: all input vectors must have the same length');
end
elseif(isscalar(varargin{i}) && ismatrix(varargin{i}))
if(size(varargin{i},1) ~= len)
error('sp_plot: all input vectors must have the same length');
end
elseif(ischar(varargin{i}))
% assume every input from this point on is a property specifier
options = varargin(i:end);
nargin_to_plot = i-1;
break;
end
end
% plot the data
colors = {'r','g','b','c','m','y','k'};
xdata = 1:len;
for i=1:nargin_to_plot
if(i==1)
hold on;
end
color_idx = mod(i,length(colors));
if(color_idx == 0)
color_idx = length(colors);
end
if(isempty(options))
plot(xdata, varargin{i},colors{color_idx});
else
plot(xdata, varargin{i},colors{color_idx},options{:});
end
end
hold off;