Code covered by the BSD License  

Highlights from
smartSlice and iGSlice

image thumbnail

smartSlice and iGSlice

by

 

slice into irregular grids with smartSlice and iGSlice. NaN values are allowed.

h=smartSlice(varargin)
function h=smartSlice(varargin)
%SmartSlice volumetric slice plot into an irregular volume.
%  SmartSlice(X,Y,Z,V,Sx,Sy,lim) draws slices along the x,y directions
%    by finding the nearest x,y grid planes to the points specified 
%    in Sx,Sy. X,Y,Z are 3D arrays defining the coordinates of V. They must
%    be of equal size but do not need to be monotonic, and may contain NaN.
%   
%    lim sets the limit of the search for nearby grid planes. For example,
%    if a typical xy cell size is 10, the correct limit would be 4.9. A
%    larger limit may return more than 1 possible plane, in which case the
%    first index is chosen.
%
%
[cax,args,nargs] = axescheck(varargin{:}); % Future update should allow user to specify axes
error(nargchk(7,7,nargs,'struct'));
nin = nargs;

if nin ~= 7
    error(id('WrongNumberOfInputs'),'Wrong number of input arguments.')
elseif nin == 7 
    v = args{4};
    args{4} = [];
    if ndims(v)~=3, error(id('InvalidVDims'),'V must be a 3-D array.'); end
    [x,y,z] = deal(args{1:3});
    [sx,sy] = deal(args{5:6});
    lim=args{7};
end
sze=size(x);
if sx
    for i = 1:length(sx)
    j=find(x<=(sx(i)+lim) & x>=(sx(i)-lim));
    if isempty(j)
        sxx(i)=0;
    else
        [~,sxx(i),~]=ind2sub(sze,j(1));
    end
    end
end
if sy
    for i =1:length(sy)
    j=find(y<=(sy(i)+lim) & y>=(sy(i)-lim));
    if isempty(j)
        syy(i)=0;
    else
        [syy(i),~,~]=ind2sub(sze,j(1));
    end
    end
end

    h=quickSlice(x,y,z,v,sxx,syy);
if nargout > 0
    hout = h;
end
function str=id(str)
str = ['MATLAB:slice:' str];

Contact us