File Exchange

image thumbnail

Quiver - magnitude depending color in 2D and 3D

version 1.0.3 (4.33 KB) by Jonas Krimmer
Implements the MATLAB given quiver/quiver3 function adding a color coding depending on magnitude

89 Downloads

Updated 24 Nov 2019

View License

Package contains quiverC2D and quiverC3D.
This package has been inspired by Quiverc. In some cases Quiverc is even expected to be faster than quiverC2D. My intention was to use MATLABs own quiver function to make the way the script works easily understandable.

quiverC3D creates a 3D quiver plot and adds a color coding. The color coding is
given by the absolut values of the component vectors. Large values result in colors
from the upper end of the used colormap. Plotting parameters have to be changed within
the function in this version. Values equal to NaN or inf are set to zero.
In case of complex arrays the real part is used.
INPUT:
x - 2D matrix, x components of initial points
y - 2D matrix, y components of initial points
z - 2D matrix, z components of initial points
u - 2D matrix, x components of arrows
v - 2D matrix, y components of arrows
w - 2D matrix, z components of arrows
maxNumArrows - a positive integer (non-integer should work as well)
number limiting the maximum number of plotted arrows. Since vectors
of length zero aren't plotted and the matrices are sampled
uniformly, it's possible that fewer arrows will be visible in the
end. If maxNumArrows is not given its value is set to 1000.

OUTPUT:
none

WARNING!: Using large datasets in combination with choosing maxNumArrows
very large might result in this script running forever.

--------------------------------------------------------------------------------------

EXAMPLE:
[x,y] = meshgrid(linspace(0,10,100),linspace(0,10,100));
z = sin(x.^2 + y.^2);
u = exp(-0.2*(x-5).^2 - 0.2*(y-5).^2);
v = -u;
w = u.*v;
quiverC3D(x,y,z,u,v,w,500);

--------------------------------------------------------------------------------------

See also: QUIVER3, LINESPEC, COLORMAP.

Cite As

Jonas Krimmer (2019). Quiver - magnitude depending color in 2D and 3D (https://www.mathworks.com/matlabcentral/fileexchange/58527-quiver-magnitude-depending-color-in-2d-and-3d), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Jonas Krimmer

@David Robinson: That's probably because I had to turn off the automatic scaling of the quiver plots. The results should be the same as if you ran quiver(x, y, u, v, 0). Further, there was an automatic normalization enabled. Updated version is available with a more reasonable(?) normalization, which can easily be switched on and off!

Great function, but it does not appear to keep the integrity of the u and v magnitudes when plotting. The direction remains consistent, but a vector on the quiverC2D function has a different u and v component than the same vector has on the regular quiver function. Any idea why this may be?

Jonas Krimmer

@plasmageek: Honestly, I have no idea why there was this check for positive values included. It's been a while since I've written this function. Thank you for your remark, this condition is removed in the newest version.
If you would still need some help: Could you provide some more insight in what exactly you are trying to do? Otherwise, it will be hard to help you..

plasmageek

Hmm can't get this to work. It's not giving any errors, but all I get is a blank, white figure. I noticed there was a command checking for only positive values of the velocities (WHY??!!!??) and tried taking that out, but it still gives the same result.

Amlan Das

Hsin Chang

Updates

1.0.3

From now on: No automatic normalization. In case of normalization, the longest vector will now be plotted with length one.

1.0.2

Function is now more intelligent: Creates grouped quiver plots if arrays contain more elements than the colormap. Enables plotting of thousands of arrows without major issues.

1.0.1

- Fixed a bug where the colormap was assumed to carry a fixed number of 64 colors.
- Fixed a bug in quiverC3D leading to an incorrectly calculated vector magnitude.

1.0.0.0

2016_08_03: Updated description.

MATLAB Release Compatibility
Created with R2016a
Compatible with R2016a to R2019b
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Quiverc