function h=quiver_scaled(x,y,u,v)
%QUIVER_SCALED Scaled quiver plot.
%   quiver_scaled(x,y,u,v) calls the Matlab quiver plot function in such a
%   way as to get nice looking arrow heads in the case of x and y dimensions
%   of different orders of magnitude even in older versions of Matlab
%
%   See also QUIVER

%   Ian Bruce (ibruce@ieee.org)
%   Written November 2004; Updated November 2005 to work with Matlab v7.x

xrange = max(max(x))-min(min(x)); % Compute the range of x values
yrange = max(max(y))-min(min(y)); % Compute the range of y values

scale_factor = xrange/yrange;  %  Compute a scale factor based of the ratio
%  of the x-range to the y-range

vers_text = version('-release');

if (strncmp(vers_text,'20',2))
    if eval(vers_text(1:4))>=2013
        h=quiver(x,y,u,v,0.5);
        hs = get(h,'MaxHeadSize');
        set(h,'MaxHeadSize',hs/scale_factor)
    else
        h=quiver('v6',x,y*scale_factor,u,v*scale_factor); %  Call the quiver function with scaled data
        ydata = get(h(1),'ydata');  %  Get the handle for the y data points of the arrow lines
        set(h(1),'ydata',ydata/scale_factor);  %  Re-scale the y data points of the arrow lines
        ydata = get(h(2),'ydata');  %  Get the handle for the y data points of the arrow heads
        set(h(2),'ydata',ydata/scale_factor);   %  Re-scale the y data points of the arrow heads
    end
elseif (eval(vers_text)>13)
    h=quiver('v6',x,y*scale_factor,u,v*scale_factor); %  Call the quiver function with scaled data
    ydata = get(h(1),'ydata');  %  Get the handle for the y data points of the arrow lines
    set(h(1),'ydata',ydata/scale_factor);  %  Re-scale the y data points of the arrow lines
    ydata = get(h(2),'ydata');  %  Get the handle for the y data points of the arrow heads
    set(h(2),'ydata',ydata/scale_factor);   %  Re-scale the y data points of the arrow heads
else
    h=quiver(x,y*scale_factor,u,v*scale_factor); %  Call the quiver function with scaled data
    ydata = get(h(1),'ydata');  %  Get the handle for the y data points of the arrow lines
    set(h(1),'ydata',ydata/scale_factor);  %  Re-scale the y data points of the arrow lines
    ydata = get(h(2),'ydata');  %  Get the handle for the y data points of the arrow heads
    set(h(2),'ydata',ydata/scale_factor);   %  Re-scale the y data points of the arrow heads
end
