What is the difference between these two scripts; and which one is more appropriate to use

2 views (last 30 days)
% the dataset is *u = squeeze(tdata(1,:,:)./10); v = squeeze(tdata(2,:,:)./10);*
%1st
nu = u.*cos(rlong) + v.*sin(rlong);
nv = -u.*sin(rlong) + v.*cos(rlong);
R = sqrt(nu.*nu + nv.*nv);
% 2nd
[TH,R] = cart2pol(v,u);
D = rad2deg(TH);

Answers (1)

Roger Stafford
Roger Stafford on 18 Mar 2016
Edited: Roger Stafford on 18 Mar 2016
In "u = squeeze(tdata(1,:,:)./10);" the first level of the first dimension of three-dimensional 'tdata' is divided by 10 and converted into a two dimensional matrix. The 'v' is the same for the second level of that first dimension.
In the second pair, the coordinate axes for the point (u,v), (or rather the matrices of points,) is rotated counterclockwise by radian angle 'rlong' and (nu,nv) are the coordinates with respect to these new axes. The third equation gives the euclidean distance of the points from the origin.
In the third pair the first of the pair converts each of those original cartesian coordinates into polar coordinates. The second changes each of the angles in the polar coordinates from radian measure to degree measure. (It would appear the cartesian coordinates here are in reverse order.)
Asking which is the more appropriate is a meaningless question in this context. They all act together as a unified whole.
An alternate interpretation of the second pair is that all the points have been rotated clockwise by radian angle 'rlong' and (nu,nv) are their rotated cartesian coordinates with respect to the original axes.
  3 Comments
Roger Stafford
Roger Stafford on 18 Mar 2016
Your equations only make sense if u and v are cartesian components of velocity vectors, not vectors themselves. But if all you want is the magnitude of each velocity vector, why not just do this:
R = sqrt(u.^2+v.^2);
It would give you a matrix of magnitudes. Why bother with rotations and 'cart2pol'?
Sophia
Sophia on 18 Mar 2016
Edited: Sophia on 18 Mar 2016
The dataset i am using says in its description, here is the link
https://nsidc.org/data/docs/daac/nsidc0116_icemotion.gd.html
Here are the details of the projection-
https://nsidc.org/data/ease/ease_grid.html
The reason why i need to do this, because u and v values change with the change in hemisphere. i.e. from W to E, cuz of the EASE Grid Projection

Sign in to comment.

Categories

Find more on 3-D Scene Control in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!