MATLAB Answers

quiverm miscalculates some angles?

2 views (last 30 days)
K on 15 Jul 2012
Commented: Chad Greene on 18 Jun 2014
I am using quiverm to plot directions given by (u,v) coordinates. The mapped directions look fine when u and v are both positive or both negative. The mapped directions are incorrect if either u or v are negative. Any suggestions? (Here is my code; yes, I'm new to MATLAB):
%Clear and close all files, windows, etc.
close all;
lat=[43.63, 24.55, 47.93, 35.22, 37.62, 25.90, 32.73];
lon=[-70.30, -81.75, -124.57, -75.62, -122.40, -97.42, -117.17];
u=[0.4209, 0.1473, 0.2935, 0.5070, 0.3087, -0.1520, -0.3779];
v=[-0.2750, -0.4750, 0.6447, 0.5786, 0.3922, 0.8671, -0.3376];
%Create a vector of State Names for plotting
stuse={'Maine' 'New Hampshire' 'Massachusetts' 'Rhode Island' 'Connecticut'...
'New York' 'Pennsylvania' 'New Jersey' 'Delaware' 'Maryland' 'Virginia'...
'North Carolina' 'South Carolina' 'Georgia' 'Florida' 'Alabama'...
'Mississippi' 'Louisiana' 'Texas' 'California' 'Oregon' 'Washington'};
%Create a map
ax = usamap(stuse);
set(ax, 'Visible', 'off')
latlim = getm(ax, 'MapLatLimit');
lonlim = getm(ax, 'MapLonLimit');
states = shaperead('usastatehi',...
'UseGeoCoords', true, 'BoundingBox', [lonlim', latlim']);
geoshow(ax, states,'FaceColor','white')
grid off;
%scale u,v components so they all have the same magnitude (1.0)
for i=1:7
%change arrow length according to variable 'length'
%plot arrows
The arrow for Portland ME (lat 43.63) should be pointing to 327 degrees; the arrow for Key West FL (lat 24.55) should be pointing to 287 deg; and the arrow for Brownsville TX (lat 25.90) should be pointing to 100 deg.
The arrows for Quillayute WA (lat 47.93), Cape Hatteras NC (lat 35.22), San Francisco CA (lat 37.62), and San Diego CA (lat 32.73) are plotted correctly.


Sign in to comment.

Accepted Answer

Chad Greene
Chad Greene on 22 May 2014
Edited: Chad Greene on 22 May 2014
The reason it looks right when both components are positive or both are negative, is because you're tricking yourself into believing those are correct, when in fact they're just pointing to the correct quadrant. Unfortunately, u and v are switched from convention in the quiverm function. So you need to switch your lu and your lv.
Alternatively, the ncquiverref function should fix that issue as well as eliminate the headaches of scaling your vectors manually.


K on 18 Jun 2014
Thanks for your answer and for pointing me to ncquiverref. That is a great tool for us earth scientists; unfortunately it is written for regularly spaced grid points whereas I'm trying to plot vectors at irregularly spaced geographic locations. Perhaps I can use it as a template for writing my own code. That is, once I get to be a better MATLAB programmer.
Chad Greene
Chad Greene on 18 Jun 2014
Ah, good catch! Sorry to lead you astray. Again, you may simply switch your lu and lv and use quiverm.

Sign in to comment.

More Answers (0)



Translated by