function [majrax,majaz,minrax,minaz,elptcty]=pcaben(u,v) % Principal components of 2-d (e.g. current meter) data % %Called by elpspam.m to calculate ellipse parameters - B.G. 2000 % %Inputs: u and v (eastward and northward current velocities) % %outputs: major axis (majrax) minor axis (minrax) % major azimuth (majaz) minor azimuth (minaz) % elipticity (elptcty) % % function pca(u,v,[[s],ipost]) % % u and v are column vectors with x and y data % s is an optional length for the axes % ipost is an optional flag 0=no action, 1=plot input data % % Chris Sherwood, USGS % March 17, 1999 % % Modified by jpx on 6-14-99 to be used in CMGTooL % Modified by jpx on 10-14-99 to plot ellipses % 2/16/2000 modified by Ben Gutierrez to incorporate into LTM work. % -ipost and [s] no longer necessary to this rountine which is based on PCA.M which is included in % CMGTool. % mu = mean(u); mv = mean(v); C = cov(u,v); [V,D] = eig(C); x1 = [.5*sqrt(D(1,1))*V(1,1);-.5*sqrt(D(1,1))*V(1,1)]; y1 = [.5*sqrt(D(1,1))*V(2,1);-.5*sqrt(D(1,1))*V(2,1)]; x2 = [.5*sqrt(D(2,2))*V(1,2);-.5*sqrt(D(2,2))*V(1,2)]; y2 = [.5*sqrt(D(2,2))*V(2,2);-.5*sqrt(D(2,2))*V(2,2)]; [mspd mdir]=pcoord( mu, mv ); for i=1:2 eval(['[ leng(i), az(i) ] = pcoord( x' num2str(i) '(1), y' num2str(i) '(1) );']); end; if leng(1)>=leng(2) majr=leng(1);majaz=az(1); minr=leng(2);minaz=az(2); else majr=leng(2);majaz=az(2); minr=leng(1);minaz=az(1); end; majrax = majr*2; minrax = minr*2; elptcty = (1 - minr/majr);