Repository navigation
Expand file tree
/
Copy pathplotshaded.m
More file actions
53 lines (46 loc) · 1.38 KB
/
Copy pathplotshaded.m
File metadata and controls
53 lines (46 loc) · 1.38 KB
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
function plotshaded(x,y,fstr,levels,outliers)
% 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];plotshaded(x,[sin(x.*1.1)+1;sin(x*.9)-1],'r');
if nargin < 5
if exist('outliers','var') == 0
outliers = 0;
else
error('plotshaded:argChk','Wrong number of input arguments');
end
end
if nargin < 4
if exist('levels','var') == 0
levels = 1;
else
error('plotshaded:argChk','Wrong number of input arguments');
end
end
elements = size(y,1);
Datmean = mean(y);
Datminimum = min(y);
Datmaximum = max(y);
Datmin = min(y);
Datmax = max(y);
px=[x,fliplr(x)];
py=[Datmin, fliplr(Datmax)];
patch(px,py,1,'FaceAlpha',0.7*(1/(levels+1)),'FaceColor',fstr,'EdgeColor','none');
y = sort(y);
y([1:floor(elements*outliers/2),size(y,1)-floor(elements*outliers/2)+1:size(y,1)],:) = [];
for i = 1:levels
Datmin = min(y);
Datmax = max(y);
px=[x,fliplr(x)];
py=[Datmin, fliplr(Datmax)];
patch(px,py,1,'FaceAlpha',0.7*(1/(levels+1)),'FaceColor',fstr,'EdgeColor','none');
y = sort(y);
y([1:floor(elements/levels/2),size(y,1)-floor(elements/levels/2)+1:size(y,1)],:) = [];
hold on
end
plot(x,Datmean,fstr,'LineWidth',1.5);
spread = max(Datmaximum) - min(Datminimum);
axis([min(x), max(x), min(Datminimum) - 0.1 * spread, max(Datmaximum) + 0.1 * spread])
end