View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
quivermc

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.83333
4.8 | 6 ratings Rate this file 33 Downloads (last 30 days) File Size: 833 KB File ID: #47314 Version: 1.4
image thumbnail

quivermc

by

Chad Greene (view profile)

 

22 Jul 2014 (Updated )

Plot georeferenced vector fields with color options.

| Watch this File

File Information
Description

quivermc is an adapted version of Andrew Roberts' ncquiverref. Dr. Roberts' function and this function fix a couple of problems with Matlab's quiverm function. The two primary reasons you should never use quiverm are as follows:
1. Matlab's quiverm confoundingly mixes up u and v. By convention in the Earth sciences, u is the zonal component where eastward is positive and v is the meridional component where northward is positive. Matlab gets this wrong, but the quivermc function described here gets it right.

2. For reasons related to ship travel and some old legacy code from Navy guys decades ago, Matlab's quiverm scales vectors in a strange way that depends on latitude. If you're plotting some absolute field like wind vectors, there is no physical reason that you would want to scale vectors in such a way that their zonal components shrink to zero at the poles.

In addition to fixing the problems described above, quivermc also allows a few extra options including color settings, arrow density, and options for displaying converging or diverging flow.

Acknowledgements

Quiverc, Quiverc2, Quiverc2wcmap, Quiverc, Quiverc.M Updated With New Features, Quiverwcolorbar, Ncquiverref, and Calcticks inspired this file.

This file inspired Antarctic Mapping Tools and Circlem.

Required Products Mapping Toolbox
MATLAB
MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
18 Apr 2016 Chad Greene

Chad Greene (view profile)

Hi Asma,

The "Undefined function..." error message almost always means Matlab can't find the function. Make sure you download, unzip, and put quivermc somewhere Matlab can find it.

Comment only
17 Apr 2016 asma

asma (view profile)

Dear Chad i test your code without changing any thing but i get " Undefined function or method 'quivermc' for input arguments of type 'double'.

Error in ==> Untitled at 108
quivermc(lat,lon,u,v)??
i wanna know what's the problem?

Comment only
22 Jan 2016 Chad Greene

Chad Greene (view profile)

Hi Oliver,

Thanks for bringing this to my attention. I have never worked with orthographic projections before, but you are exactly right. I wish I could offer some elegant solution, but nothing immediately comes to mind, unless you can figure out which vectors are on the other side of the globe and NaN-out those values.

On a philosophical note, an orthographic projection may not be the best choice for showing vector fields. The vector field is plotted in 2D space where equal length is given to equal vector magnitudes everywhere in the map, whereas orthographic projections are distorted toward the horizon of the globe. Mixing and undistorted vector fields with distorted space may be confusing for the viewer to interpret.

Nonetheless, if you find a good solution to the problem of quivermc plotting on all sides of an orthographic projection, please let me know.

Chad

Comment only
22 Jan 2016 Oliver

Oliver (view profile)

Dear Chad

Thanks for this nice routine.

One problem: When you set axesm('ortho') quivermc also draws "hidden" vectors (on the backside of the hemisphere).

Do you have any suggestions for improving this?

Thanks in advance for any comments!

Comment only
19 Nov 2015 Liya Wang

Hi Chad,
Thank u for your answer.

I get your point of the first question .

I must draw all the arrows,and my u,v have lots of NaN,so each arrow will not only be about a pixel in width. Why can I draw all arrows using quiverm although they look not good.

I tried to delete all NaN ,and reshape u,v,lon,lat,and I can use your function to draw all arrows,but there is another question,the number of NaN is not the same when I have many different u,v.

Comment only
18 Nov 2015 Chad Greene

Chad Greene (view profile)

Hi Liya,

Matlab's quiverm mixes up u and v because by convention in Earth Science, u is the zonal component and v is the meridional component. However, Matlab's quiverm goes against convention and defines u as the meridional component and v as the zonal. Matlab's quiverm also scales the arrows by latitude, but that's a different problem.

You probably do not want to plot all 608x896 arrows in your field for two reasons:

1. Plotting over half a million arrows hogs computational resources.

2. More importantly, what are the dimensions of your figure? If your figure is 1000 pixels wide, that means each arrow can only be about a pixel in width. A one-pixel arrow will not look like an arrow, it will look like a tiny dot.

Comment only
18 Nov 2015 Liya Wang

Hi Chad.
Thank u for sharing your code.I want to ask you some questions.

First,you say matlab's quiverm confoundingly mixes up u and v. But I use quiverm to draw arrows correctly.Why did you think matlab is wrong?

Second,my u matrix is 608*896,how can I get the full arrows.I tried to modify your code,changed the defaultWidth 50 to 1000,and changed DensityVal 100 to 1000.But the output is wrong.Hope to get your precious answer.

Thanks in advance for any help,

liya Wang

30 Sep 2015 Chad Greene

Chad Greene (view profile)

Hi John,

That's a great question worth clarifying. Inputs lat and lon can only have units of degrees, but u and v can have just about any units *except* degrees. So u and v in meters per second or miles per hour or angstroms per fortnight are perfect for quivermc.

I wrote quivermc because Matlab's inbuilt quiverm function only accepts velocities in degrees, which is absolutely nonsensical for most real-world applications. You can absolutely use quivermc for wind data without needing to do any silly latitude-dependent scaling.

There are a couple of examples in the html documentation file (the light bulb icon on this page) that show how you can even label a reference arrow with any units you'd like.

Let me know if you have any more questions.

Chad

Comment only
30 Sep 2015 John Hader

Chad,

Thanks for the awesome submission.

I have a question about the format of the input arguments u and u.

I am trying to overlay wind vectors on a map (generated with geoshow), with the wind vector locations given by lat and lon matrices (in degrees) and the u and v components given in meters per second.

The ncquiverref function requires that the location matrices for the vectors be in the same units as the u and v component (i.e. if the locations of the vectors are in degrees, the u and v components have to be in degrees, whereas if the locations are in Cartesian units the u and v components must be in Cartesian units).

Do the u and v inputs for quivermc have to be in degrees lon and degrees lat per unit time (respectively), as the location inputs are in degrees? I see in your conversation with Gino below that the coordinates (I'm assuming this is just the location matrices?) cannot be in Cartesian units, but I was not able to find anywhere in the documentation that u and v had to be in any particular units.

Thanks in advance for any help,

John

11 Aug 2015 Chad Greene

Chad Greene (view profile)

Hi Suene,

Quivermc needs to know where every arrow should be placed. You seem to have information about the size and direction of 144 x ? arrows, but your missing information about where those arrows belong. I wish I could be more helpful, but it sounds like your dataset is incomplete. It is difficult to know without any more information.

Good luck!
Chad

Comment only
11 Aug 2015 Suene

Suene (view profile)

Hi, Chad!

Many thanks for sharing this routine!It is great.

I have a question.

>> quivermc(lat,lon,u,v)
Error using quivermc (line 143)
Dimensions of lat, lon, u, and v must agree.

In my case, lon, u and v have the same lenght 144. But the lat has 73. What can I do to solve that?

Any help or suggestion will be greatly appreciated.

21 Jul 2015 Chad Greene

Chad Greene (view profile)

Hi Gino,

It looks like you are plotting in cartesian coordinates. quivermc is for map coordinates. If you have the mapping toolbox, initialize a map first with the worldmap function. If you do not have the Mapping Toolbox, I think you'll need to use one of the other quiver functions on the File Exchange site. Good luck!

Comment only
20 Jul 2015 Gino

Gino (view profile)

Hi Chad,

Great addition to ncquiverref, thanks !!!

I have a question regarding an error I keep getting:
??? Error using ==> quivermc at 247
Current axes must be map axes.

I'm plotting WRF wind vectors. The WRF data is on a Lambert conformal conic projection. I'm using the function toposurf (http://mooring.ucsd.edu/software/matlab/doc/map/toposurf.html) to plot a map of 2 meters air temperature and trying to plot the wind vectors on top. I've being using ncquiverref to plot the wind vectors with success, but I need to make the arrows a thicker and the "divergent" option will help better display my data.

Any help or suggestion will greatly appreciated.

Comment only
15 Dec 2014 Ehsan Sadighrad

Thanks, this is excellent.

21 Aug 2014 Chad Greene

Chad Greene (view profile)

Leyon, that is an excellent suggestion. I've now included some options for colorbars. Thanks for the tip!

Comment only
15 Aug 2014 Leyon

Leyon (view profile)

Very nice function. A suggestion to improve your function is to scale the colorbar xticks based on the reference value rather than 0:1. It would eliminate the need for the user to do the multiplication.
Here is the snippet of code I use to do such a task:

set(cb, 'xticklabel', get(cb, 'xtick') * refval);

cb is a handle to the colorbar or in your case can be turned on if the option colormap is defined in line 331.

06 Aug 2014 Chad Greene

Chad Greene (view profile)

Not to be confused with this guy: https://www.youtube.com/watch?v=ljB_q-XjSp4

Comment only
29 Jul 2014 Warwick

Good quiver plot function with excellent range of options.

Updates
24 Jul 2014 1.1

Removed 'refvec' 'on' or 'off' style. Now a reference vector is printed only when units are declared.

29 Jul 2014 1.2

Now includes linewidth option and more arrow size scaling options.

21 Aug 2014 1.3

Now includes options for colorbar formatting, made possible in part by John Barber's calcticks function.

22 Aug 2014 1.4

Typo fix in example file.

Contact us