Home > bobstuff > rotmajax.m

rotmajax

PURPOSE ^

ROTMAJAX rotates input vector velocity into direction of maximum variance.

SYNOPSIS ^

function [ur,vr,thetad]=rotmajax(u,v)

DESCRIPTION ^

 ROTMAJAX rotates input vector velocity into direction of maximum variance.

 [ur,[vr],thetad]=ROTMAJAX(u,v) rotates input vector velocity
 into direction of maximum variance.  Input can be either real 
 u,v or complex (u+iv) vectors, ur,vr or (ur+ivr) is the vector 
 velocity rotated by the angle theta counterclockwise.  Assumes 
 u,v are east,north components. 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 ver. 1: 11/17/96 (RG)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001   function [ur,vr,thetad]=rotmajax(u,v)
0002 
0003 % ROTMAJAX rotates input vector velocity into direction of maximum variance.
0004 %
0005 % [ur,[vr],thetad]=ROTMAJAX(u,v) rotates input vector velocity
0006 % into direction of maximum variance.  Input can be either real
0007 % u,v or complex (u+iv) vectors, ur,vr or (ur+ivr) is the vector
0008 % velocity rotated by the angle theta counterclockwise.  Assumes
0009 % u,v are east,north components.
0010 %
0011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0012 % ver. 1: 11/17/96 (RG)
0013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0014 
0015 if nargin==1;
0016     v=imag(u);
0017     u=real(u);
0018 end
0019 
0020 [N,M]=size(u);
0021 if M==1
0022   u=u';v=v';
0023 end
0024 
0025 if any( isnan(u(:)))|(isnan(v(:)) )
0026      disp('NaNs found')
0027       ur=oness(u)*nan;
0028       vr=ur;
0029      g=find( (~isnan(u(:)))&(~isnan(v(:))) );
0030   if length(g)>1;
0031      u=u(g);
0032       v=v(g);
0033   end
0034 else
0035      ur=u;
0036      vr=u;
0037      g=1:length(u(:));
0038 end
0039 if length(g)>1
0040 cv1=cov([u(:) v(:)]);
0041 theta=0.5*atan2(2.*cv1(2,1),(cv1(1,1)-cv1(2,2)) );
0042 thetad=theta*180./pi
0043 vr(g)=-u*sin(theta)+v*cos(theta);
0044 ur(g)=u*cos(theta)+v*sin(theta);
0045 
0046 else;
0047 thetad=nan;
0048 end
0049 
0050 if M==1
0051   ur=ur';vr=vr';
0052 end
0053 
0054 if nargin==1
0055    ur=ur+sqrt(-1)*vr;
0056    vr=thetad;
0057    thetad=[];
0058 end

Generated on Thu 01-Dec-2005 07:46:03 by m2html © 2003