Code covered by the BSD License  

Highlights from
ncquiverref

4.66667

4.7 | 7 ratings Rate this file 25 Downloads (last 30 days) File Size: 5.74 KB File ID: #17582
image thumbnail

ncquiverref

by Andrew Roberts

 

18 Nov 2007 (Updated 14 Feb 2011)

Quiver (vector) with a reference vector or color code on a map or Cartesian axes.

| Watch this File

File Information
Description

This function is a substitute for the standard versions of quiver and quiverm available using a vanilla release of matlab. This version assumes a 2D vector field is being plotted using a gridded flow field from a numerical model. It is primarily intended for Earth System Model analysis.

The function enables the scaling of vectors according to a reference vector plotted in the lower right hand corner of the plot axes. The function works for both map and Cartesian axes and allows the color of vectors to be changed.

If a reference value is not provided, the reference value is calculated by rounding the median or maximum magnitude of the quiver vectors. Scaling of vectors still occurs even if the reference vector plotting is switched off. This enables different subplots to share identical scaling so that the relative magnitude of vectors can be compared between subplots (provided they share the same grid).

The function also includes the ability to plot color vectors, all of equal length but color coded according to their magnitude. In this case, a colorbar is provided, complete with units, and no scaling vector is plotted.

Vectors are centered on the grid points they represent, rather than the tail of the arrow being positioned on the grid point as is the case for the vanila Matlab quiver and quiverm versions.

Required Products Mapping Toolbox
MATLAB release MATLAB 7.11 (2010b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
02 Jul 2009 Ibrahim M

This is genius!

For it to work in multiple colors, you make sure your x and y are produced with/as meshgrid. Also specify your colors according to your choice of colorbar. Eg if your caxis ([15 30]) for SST, then you should have the function as:

ncquiverref(x,y,xx,yy, 'DegC','mean',0,'col',[15 20 25 30]);

Nice work Andrew!

Thank you very much for sharing!!

Ibrahim

25 Sep 2009 Jason Sippel  
02 Oct 2009 Jason Sippel

Great code! After chatting with the author, I have found that the below addendum is useful for plotting a small subdomian of model output. This would be useful if, for example, you are tracking a tropical cyclone in a Lagrangian system with ilat,flat,ilon, and flon sampled from your model grid based on the number of grid points from the storm center.

If you don't do something similar to this, the physical size of the map frame on the screen may not match from one figure to the next.

Here's the code:

    tightmap
    xlim=get(gca,'xlim');
    ylim=get(gca,'ylim');
    
   cutfactor = 1.3;
   xcenter=mean(xlim);
   xoffset=diff(xlim)/2;
   ycenter=mean(ylim);
   yoffset=diff(ylim)/2;
   set(gca,'Xlim',[xcenter-cutfactor*xoffset xcenter+cutfactor*xoffset]);
   set(gca,'Ylim',[ycenter-cutfactor*yoffset ycenter+cutfactor*yoffset]);

20 Feb 2010 Chong Zhou

Genius work! It gives amazing visualisation of large amount of vectors, which is common in the data post-processing in article image velocimetry (PIV). The author also improved the code to better adapt to the application in PIV, where 'axis ij' is a must to plot pixel coordinate.

Again, great work and I strongly suggest people using PIV try this code!

Many thanks!

01 Sep 2010 Hamed Babazadeh Babazadeh

Great code, just a question,

how to scale vector field as it is in quiver command, the default size of vectors is too much for my application.

Thanks

01 Sep 2010 Andrew Roberts

Hi Hamed,

If you have tested using "max" instead of "median" for reftype, or your color vectors are too long, it is easy to adjust the variable "scalelength" to a fraction of its current value in the code. Change line 186 to:
scalelength=X*min(mean(z1(~isnan(z1))),mean(z2(~isnan(z2))));
where 0<X<1.
The main reason you may have to make this manual adjustment is if your vector magnitudes are strongly negatively skewed.

cheers
Andrew

21 Jan 2011 Thibaut Leroy  
25 Jan 2011 Josh Jones  
25 May 2011 Cheryl Harrison

Is there any way to get this to plot vectors over a pcolor plot? I can get the vectors on just fine, but as soon as I plot the reference vector it whites everything out. Modification ideas?

Please login to add a comment or rating.
Updates
21 Jan 2009

This is a complete rewrite of the originally posted function. Vectors are generated within this function rather than using quiver and quiverm, are now centered on the grid points, and have the ability to be color coded according to their magnitude.

22 Jan 2009

This function is a complete rewrite of the originally submitted file.

19 Feb 2010

This file has been amended so that meshgrid does not need to be run prior to using the function. Also, a small bug has been fixed to allow the use of axis ij to invert the y axis for non-color plots.

20 Jan 2011

Fixed a bug that occurred when calculating the median vector magnitude when most of the field has vectors of zero length.

14 Feb 2011

Removed use of the Latex interpreter to avoid a bug in MATLAB R2010b. The Latex text interpreter may cause Matlab to crash when using the 'nodisplay' option (this bug has been reported to Mathworks).

Tag Activity for this File
Tag Applied By Date/Time
quiver Andrew Roberts 22 Oct 2008 09:35:53
reference vector Andrew Roberts 22 Oct 2008 09:35:53
legend Andrew Roberts 22 Oct 2008 09:35:53
earth sciences Andrew Roberts 22 Oct 2008 09:35:53
general Andrew Roberts 22 Oct 2008 09:35:53
color vector Andrew Roberts 21 Jan 2009 17:12:16
meteorology Andrew Roberts 21 Jan 2009 17:12:16
oceanography Andrew Roberts 21 Jan 2009 17:12:16
earth science Andrew Roberts 21 Jan 2009 17:12:16
current vector plots Alex Webb 26 Feb 2010 06:18:43
oceanography Nikos zaronikos 09 Mar 2010 07:37:35
reference vector Pavel ? 03 May 2010 11:23:11
general zifeng hu 27 Nov 2011 02:03:23

Contact us at files@mathworks.com