-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_shaded.m
More file actions
33 lines (27 loc) · 742 Bytes
/
plot_shaded.m
File metadata and controls
33 lines (27 loc) · 742 Bytes
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
function varargout = plot_shaded(x,y,fstr);
% x: x coordinates
% y: either just one y vector, or 2xN or 3xN matrix of y-data
% fstr: format ('r' or 'b--' etc)
%
% example
% x=[-10:.1:10];
% plot_shaded(x,[sin(x.*1.1)+1;sin(x*.9)-1],'r');
if size(y,2)<size(y,1)
y=y';
x=x';
end
if size(y,1)==1 % just plot one line
plot(x,y,fstr);
end;
if size(y,1)==2 %plot shaded area
px=[x,fliplr(x)]; % make closed patch
py=[y(1,:), fliplr(y(2,:))];
patch(px,py,1,'FaceColor',fstr,'EdgeColor','none');
end;
if size(y,1)==3 % also draw mean
px=[x,fliplr(x)];
py=[y(1,:), fliplr(y(3,:))];
patch(px,py,1,'FaceColor',fstr,'EdgeColor','none');
plot(x,y(2,:),'Color', fstr);
end;
alpha(.2); % make patch transparent