scale_quivers

Version 1.0.1 (1.58 KB) by Michael Xie
Scales multiple quiver plots to use the same length scale.
130 Downloads
Updated 8 Nov 2018

View License

SCALE_QUIVERS(QH, SCALE) scales multiple quiver plots to use the same length scale (by default, the longest vector)
QH is a vector of handles to the quiver plots. Note that a handle of a quiver plot can be easily obtained via 'qh = quiver(...)'.
SCALE is a user-defined final scaling factor. Once the vectors have been equally scaled between the subplots, the arrow lengths are then multiplied by this value.
-------------------------------------------------------------------------------------
Use case:
The user has multiple quivers which should be scaled the same.
The built-in QUIVER command can turn off autoscale for all quivers so that they are scaled the same. However, some vector arrows may have an inappropriate length (too large and overlapping or too small). Since autoscale is off, there is no easy way to rescale ALL vector arrows concurrently.
SCALE_QUIVERS addresses this issue. This function only needs to be called once near the end of the script after all relevant quivers have been plotted.
-------------------------------------------------------------------------------------
Example:
load wind
a = cellfun(@(x) x(1:end,1:end,1), {x,y,z, u,v,w}, 'uniformoutput',0);
x = a{1}; y = a{2}; z = a{3};
u = a{4}; v = a{5}; w = a{6};
u2 = u/2; v2 = v/2; w2 = w/2;

subplot(2,2,1)
q1 = quiver(x,y,u,v,0); title('original (autoscale off)')
subplot(2,2,2)
q2 = quiver(x,y,u2,v2,0); title('halved (autoscale off)')

subplot(2,2,3)
q3 = quiver(x,y,u,v,0); title('original (scaled by 30)')
subplot(2,2,4)
q4 = quiver(x,y,u2,v2,0); title('compressed (scaled by 30)')

scale_quivers([q3,q4],30)
-------------------------------------------------------------------------------------
The current script has been tested on Windows MATLAB R2018b for six 2D quiver plots.
-------------------------------------------------------------------------------------
Known issues and ideas for future features:
If any of the quivers is 2D, then SCALE_QUIVERS will assume all quivers are 2D (and hence delete any 3-dimensional data).
The user-defined SCALE currently has no physical meaning and will hence require trial and error for it to be useful.

MATLAB Release Compatibility
Created with R2018b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Vector Fields in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.1

Minor change to screenshot.
Removed in-script licensing info.

1.0.0