annotate _misc/featureextraction/.svn/text-base/shadedplot.m.svn-base @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function [ha hb hc] = shadedplot(x, y1, y2, varargin)
matthiasm@8 2
matthiasm@8 3 % SHADEDPLOT draws two lines on a plot and shades the area between those
matthiasm@8 4 % lines.
matthiasm@8 5 %
matthiasm@8 6 % SHADEDPLOT(x, y1, y2)
matthiasm@8 7 % All of the arguments are vectors of the same length, and each y-vector is
matthiasm@8 8 % horizontal (i.e. size(y1) = [1 N]). Vector x contains the x-axis values,
matthiasm@8 9 % and y1:y2 contain the y-axis values.
matthiasm@8 10 %
matthiasm@8 11 % Plot y1 and y2 vs x, then shade the area between those two
matthiasm@8 12 % lines. Highlight the edges of that band with lines.
matthiasm@8 13 %
matthiasm@8 14 % SHADEDPLOT(x, y1, y2, areacolor, linecolor)
matthiasm@8 15 % The arguments areacolor and linecolor allow the user to set the color
matthiasm@8 16 % of the shaded area and the boundary lines. These arguments must be
matthiasm@8 17 % either text values (see the help for the PLOT function) or a
matthiasm@8 18 % 3-element vector with the color values in RGB (see the help for
matthiasm@8 19 % COLORMAP).
matthiasm@8 20 %
matthiasm@8 21 % [HA HB HC = SHADEDPLOT(x, y1, y2) returns three handles to the calling
matthiasm@8 22 % function. HA is a vector of handles to areaseries objects (HA(2) is the
matthiasm@8 23 % shaded area), HB is the handle to the first line (x vs y1), and HC is
matthiasm@8 24 % the handle to the second line (x vs y2).
matthiasm@8 25 %
matthiasm@8 26 % Example:
matthiasm@8 27 %
matthiasm@8 28 % x1 = [1 2 3 4 5 6];
matthiasm@8 29 % y1 = x1;
matthiasm@8 30 % y2 = x1+1;
matthiasm@8 31 % x3 = [1.5 2 2.5 3 3.5 4];
matthiasm@8 32 % y3 = 2*x3;
matthiasm@8 33 % y4 = 4*ones(size(x3));
matthiasm@8 34 % ha = shadedplot(x1, y1, y2, [1 0.7 0.7], 'r'); %first area is red
matthiasm@8 35 % hold on
matthiasm@8 36 % hb = shadedplot(x3, y3, y4, [0.7 0.7 1]); %second area is blue
matthiasm@8 37 % hold off
matthiasm@8 38
matthiasm@8 39 % plot the shaded area
matthiasm@8 40 y = [y1; (y2-y1)]';
matthiasm@8 41 ha = area(x, y);
matthiasm@8 42 set(ha(1), 'FaceColor', 'none') % this makes the bottom area invisible
matthiasm@8 43 set(ha, 'LineStyle', 'none')
matthiasm@8 44
matthiasm@8 45 % plot the line edges
matthiasm@8 46 hold on
matthiasm@8 47 hb = plot(x, y1, 'LineWidth', 1);
matthiasm@8 48 hc = plot(x, y2, 'LineWidth', 1);
matthiasm@8 49 hold off
matthiasm@8 50
matthiasm@8 51 % set the line and area colors if they are specified
matthiasm@8 52 switch length(varargin)
matthiasm@8 53 case 0
matthiasm@8 54 case 1
matthiasm@8 55 set(ha(2), 'FaceColor', varargin{1})
matthiasm@8 56 case 2
matthiasm@8 57 set(ha(2), 'FaceColor', varargin{1})
matthiasm@8 58 set(hb, 'Color', varargin{2})
matthiasm@8 59 set(hc, 'Color', varargin{2})
matthiasm@8 60 otherwise
matthiasm@8 61 end
matthiasm@8 62
matthiasm@8 63 % put the grid on top of the colored area
matthiasm@8 64 set(gca, 'Layer', 'top')
matthiasm@8 65 grid on