Code covered by the BSD License  

Highlights from
vecslice

image thumbnail
from vecslice by Samuel Lazerson
Plots a pseudo 3D vector field using pcolor for the out of plane component

vecslice(varargin)
function [varargout] = vecslice(varargin)
%[htitle]=VECSLICE([x,y],vx,vy,vz) Plots a slice of a vector field
%   VECSLICE plots a slice of a vector field where the component out of
%   plane (vz) is plotted as a coutour plot using a modified pcolor
%   routine.  The title indicates the value of the longest arrow.  If an
%   output argument is specified it returns the handle to the title text.
%   Note:  Requires pixplot routine
%   Example
%     vx=magic(7); % Make some arrays
%     vy=magic(7)*.75;
%     vz=magic(7)+eye(7);
%     htitle=vecslice(vx,vy,vz); % Call the function
%     tstr=get(htitle,'String'); % Get the title text
%     set(htitle,'String',['My Text ' tstr]); % Append title to title text
%
%   Version 1.0
%   Maintained by: Samuel Lazerson (lazerson@pppl.gov)
%   Date  09/14/2010

% Handle the number of arguments and create axes arrays if necessary
if (nargin<3) || (nargin>5) || ((nargin > 3) && (nargin <5))
    disp('ERROR:  Incorrect number of arguments!');
    return
elseif nargin==3
    vx=varargin{1};
    vy=varargin{2};
    vz=varargin{3};
    nx=size(vx,1);
    ny=size(vx,2);
    x=repmat((1:nx)',[1 ny]);
    y=repmat((1:ny),[nx 1]);
elseif nargin==5
    x=varargin{1};
    y=varargin{2};
    vx=varargin{3};
    vy=varargin{4};
    vz=varargin{5};
end
% First plot vz using pixplot
pixplot(x,y,vz);
% We don't need to subsample the arrows since pixplot shifts the axis by a
% half grid step.  We do need to shift x and y.
newx=x(:,:)+(x(2,1)-x(1,1))*.5;
newy=y(:,:)+(y(1,2)-y(1,1))*.5;
% Now use quiver to plot the arrows
hold on;
quiver(newx,newy,vx,vy,0.4,'Color','black','LineWidth',2);
% Now add the colorbar and legend
colorbar;
maxval=sqrt(vx.*vx+vy.*vy);
maxval=max(max(maxval));
thandle=title(['$\left(\uparrow\colon ' num2str(maxval,'%f') '\right)$']);
set(thandle,'Interpreter','latex','FontSize',20);
hold off;
if nargout==1
    varargout{1}=thandle;
end
end

Contact us