Home > FMAToolbox > Helpers > wrap.m

wrap

PURPOSE ^

wrap - Set radian angles in range [0,2pi] or [-pi,pi].

SYNOPSIS ^

function y = wrap(x,range)

DESCRIPTION ^

wrap - Set radian angles in range [0,2pi] or [-pi,pi].

  USAGE

    y = wrap(x,range)

    x              angles in radians
    range          optional:  1 for [-pi,pi] (default)
                              2 for [0,2pi]

  SEE ALSO

    See also isradians, clinspace.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %wrap - Set radian angles in range [0,2pi] or [-pi,pi].
0002 %
0003 %  USAGE
0004 %
0005 %    y = wrap(x,range)
0006 %
0007 %    x              angles in radians
0008 %    range          optional:  1 for [-pi,pi] (default)
0009 %                              2 for [0,2pi]
0010 %
0011 %  SEE ALSO
0012 %
0013 %    See also isradians, clinspace.
0014 %
0015 
0016 % Copyright (C) 2010-2011 by Michaƫl Zugaro
0017 %
0018 % This program is free software; you can redistribute it and/or modify
0019 % it under the terms of the GNU General Public License as published by
0020 % the Free Software Foundation; either version 3 of the License, or
0021 % (at your option) any later version.
0022 
0023 function y = wrap(x,range)
0024 
0025 % Check number of parameters
0026 if nargin < 1,
0027   error('Incorrect number of parameters (type ''help <a href="matlab:help wrap">wrap</a>'' for details).');
0028 end
0029 
0030 if nargin < 2,
0031     range = 1;
0032 end
0033 
0034 if ~isa(x,'double'), y = []; return; end
0035 
0036 % Determine angle in [0,2*pi]
0037 y = mod(x,2*pi);
0038 
0039 % Change range if necessary
0040 if range == 1,
0041     change = y > pi;
0042     y(change) = y(change)-2*pi;
0043 end

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