Home > FMAToolbox > Plot > PlotMean.m

PlotMean

PURPOSE ^

PlotMean - Plot mean and confidence intervals.

SYNOPSIS ^

function p = PlotMean(X,Y,L,U,style,color)

DESCRIPTION ^

PlotMean - Plot mean and confidence intervals.

  USAGE

    p = PlotMean(X,Y,L,U,style,color)

    X              abscissae
    Y              ordinates
    L              lower error level
    U              upper error level
    style          optional style (':' or '-')
    color          optional color specification (see <a href="matlab:help plot">plot</a>)

  NOTES

    Notice that L and U specifiy actual error levels rather than (relative)
    ranges, contrary to the built-in 'errorbar' where the error is in [Y-L Y+U].

    If X is empty, it is set to 1:N (where N is the length of Y). If Y is
    empty, only error limits are plotted. Conversely, if L and U are empty, only
    the mean is plotted.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function p = PlotMean(X,Y,L,U,style,color)
0002 
0003 %PlotMean - Plot mean and confidence intervals.
0004 %
0005 %  USAGE
0006 %
0007 %    p = PlotMean(X,Y,L,U,style,color)
0008 %
0009 %    X              abscissae
0010 %    Y              ordinates
0011 %    L              lower error level
0012 %    U              upper error level
0013 %    style          optional style (':' or '-')
0014 %    color          optional color specification (see <a href="matlab:help plot">plot</a>)
0015 %
0016 %  NOTES
0017 %
0018 %    Notice that L and U specifiy actual error levels rather than (relative)
0019 %    ranges, contrary to the built-in 'errorbar' where the error is in [Y-L Y+U].
0020 %
0021 %    If X is empty, it is set to 1:N (where N is the length of Y). If Y is
0022 %    empty, only error limits are plotted. Conversely, if L and U are empty, only
0023 %    the mean is plotted.
0024 
0025 % Copyright (C) 2008-2011 by Michaƫl Zugaro
0026 %
0027 % This program is free software; you can redistribute it and/or modify
0028 % it under the terms of the GNU General Public License as published by
0029 % the Free Software Foundation; either version 3 of the License, or
0030 % (at your option) any later version.
0031 
0032 if nargin < 4,
0033   error('Incorrect number of parameters (type ''help <a href="matlab:help PlotMean">PlotMean</a>'' for details).');
0034 end
0035 
0036 if nargin < 6,
0037     color = 'b';
0038 end
0039 if nargin < 5,
0040     style = ':';
0041 end
0042 
0043 nX = length(X);
0044 nY = length(Y);
0045 nL = length(L);
0046 nU = length(U);
0047 
0048 % Make sure all non-empty inputs have the same length
0049 n = [nX nY nL nU];
0050 n = n(n~=0);
0051 if isempty(n),
0052     error('At least one input must contain data (type ''help <a href="matlab:help PlotMean">PlotMean</a>'' for details).');
0053 end
0054 m = n - n(1);
0055 if any(m),
0056     error('All non-empty inputs must have the same length (type ''help <a href="matlab:help PlotMean">PlotMean</a>'' for details).');
0057 end
0058 
0059 if nX == 0,
0060     X = (1:n(1))';
0061 end
0062 
0063 hold on;
0064 % Plot mean
0065 if nY ~= 0,
0066     p = plot(X,Y);
0067     if strcmp(style,':'),
0068         set(p,'LineStyle','-','color',color);
0069     else
0070         set(p,'LineWidth',3,'color',color);
0071     end
0072 end
0073 % Plot lower error level
0074 if nL ~= 0,
0075     p = plot(X,L);
0076     if strcmp(style,':'),
0077         set(p,'LineStyle',':','color',color);
0078     else
0079         set(p,'LineWidth',1,'color',color);
0080     end
0081 end
0082 % Plot upper error level
0083 if nU ~= 0,
0084     p = plot(X,U);
0085     if strcmp(style,':'),
0086         set(p,'LineStyle',':','color',color);
0087     else
0088         set(p,'LineWidth',1,'color',color);
0089     end
0090 end
0091

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005