Home > FMAToolbox > Helpers > isradians.m

isradians

PURPOSE ^

isradians - Test if parameter is in range [0,2pi] or [-pi,pi].

SYNOPSIS ^

function test = isradians(x)

DESCRIPTION ^

isradians - Test if parameter is in range [0,2pi] or [-pi,pi].

  USAGE

    test = isradians(x)

    x              array to test (NaNs are ignored)

  OUTPUT

    range          0 if uncertain (issues a warning)
                   1 for [-pi,pi]
                   2 for [0,2pi]
  SEE ALSO

    See also wrap, clinspace.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %isradians - Test if parameter is in range [0,2pi] or [-pi,pi].
0002 %
0003 %  USAGE
0004 %
0005 %    test = isradians(x)
0006 %
0007 %    x              array to test (NaNs are ignored)
0008 %
0009 %  OUTPUT
0010 %
0011 %    range          0 if uncertain (issues a warning)
0012 %                   1 for [-pi,pi]
0013 %                   2 for [0,2pi]
0014 %  SEE ALSO
0015 %
0016 %    See also wrap, clinspace.
0017 %
0018 
0019 % Copyright (C) 2010 by Michaƫl Zugaro
0020 %
0021 % This program is free software; you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation; either version 3 of the License, or
0024 % (at your option) any later version.
0025 
0026 function test = isradians(x)
0027 
0028 % Check number of parameters
0029 if nargin < 1,
0030   error('Incorrect number of parameters (type ''help <a href="matlab:help isradians">isradians</a>'' for details).');
0031 end
0032 
0033 if ~isa(x,'double'), test = 0; return; end
0034 
0035 % Ignore NaN
0036 x = x(~isnan(x));
0037 if isempty(x), test = 0; return; end
0038 
0039 % Min and max
0040 x = x(:);
0041 m = min(x);
0042 M = max(x);
0043 
0044 % Range test
0045 if m >= -pi && M <= pi,
0046     test = 1;
0047 elseif m >=0 && M <= 2*pi,
0048     test = 2;
0049 else
0050     warning('Angles are neither in [0,2pi] nor in [-pi,pi] (make sure they are in radians).');
0051     test = 0;
0052 end

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