Mercurial > hg > octave-lojdl
changeset 7184:2f915d6cac3d
[project @ 2007-11-26 18:45:02 by jwe]
author | jwe |
---|---|
date | Mon, 26 Nov 2007 18:45:02 +0000 |
parents | c0be321eb472 |
children | 83cbff53bc96 |
files | scripts/plot/slice.m |
diffstat | 1 files changed, 81 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/slice.m +++ b/scripts/plot/slice.m @@ -17,59 +17,59 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} slice (@var{X}, @var{Y}, @var{Z}, @var{V}, @var{SX}, @var{SY}, @var{SZ}) -## @deftypefnx {Function File} {} slice (@var{X}, @var{Y}, @var{Z}, @var{V}, @var{XI}, @var{YI}, @var{ZI}) -## @deftypefnx {Function File} {} slice (@var{V}, @var{SX}, @var{SY}, @var{SZ}) -## @deftypefnx {Function File} {} slice (@var{V}, @var{XI}, @var{YI}, @var{ZI}) -## @deftypefnx {Function File} {@var{H} =} slice (...) -## @deftypefnx {Function File} {@var{H} =} slice (...,@var{METHOD}) -## Plots slice(s) of 3D data/scalar fields. Each element of then 3-dimensional -## array @var{v} represents a scalar value at a location given by the parameters -## @var{x}, @var{y}, and @var{z}. The parameters @var{x}, @var{x}, and -## @var{z} are either 3-dimensional arrays of the same size as the array -## @var{v} in the 'meshgrid' format or vectors. The parameters @var{xi}, etc -## respect a similar format to @var{x}, etc, and they represent the points -## at which the array @var{vi} is interpolated using interp3. The vectors -## @var{sx}, @var{sy}, and @var{sz} contain points of orthogonal slices of -## the respective axes. +## @deftypefn {Function File} {} slice (@var{x}, @var{y}, @var{z}, @var{v}, @var{sx}, @var{sy}, @var{sz}) +## @deftypefnx {Function File} {} slice (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}) +## @deftypefnx {Function File} {} slice (@var{v}, @var{sx}, @var{sy}, @var{sz}) +## @deftypefnx {Function File} {} slice (@var{v}, @var{xi}, @var{yi}, @var{zi}) +## @deftypefnx {Function File} {@var{h} =} slice (@dots{}) +## @deftypefnx {Function File} {@var{h} =} slice (@dots{}, @var{method}) +## Plot slices of 3D data/scalar fields. Each element of the 3-dimensional +## array @var{v} represents a scalar value at a location given by the +## parameters @var{x}, @var{y}, and @var{z}. The parameters @var{x}, +## @var{x}, and @var{z} are either 3-dimensional arrays of the same size +## as the array @var{v} in the "meshgrid" format or vectors. The +## parameters @var{xi}, etc respect a similar format to @var{x}, etc, +## and they represent the points at which the array @var{vi} is +## interpolated using interp3. The vectors @var{sx}, @var{sy}, and +## @var{sz} contain points of orthogonal slices of the respective axes. ## ## If @var{x}, @var{y}, @var{z} are omitted, they are assumed to be -## @code{x = 1 : size (@var{v}, 2)}, @code{y = 1 : size (@var{v}, 1)} and -## @code{z = 1 : size (@var{v}, 3)}. +## @code{x = 1:size (@var{v}, 2)}, @code{y = 1:size (@var{v}, 1)} and +## @code{z = 1:size (@var{v}, 3)}. ## ## @var{Method} is one of: ## -## @table @asis -## @item 'nearest' +## @table @code +## @item "nearest" ## Return the nearest neighbour. -## @item 'linear' +## @item "linear" ## Linear interpolation from nearest neighbours. -## @item 'cubic' +## @item "cubic" ## Cubic interpolation from four nearest neighbours (not implemented yet). -## @item 'spline' -## Cubic spline interpolation--smooth first and second derivatives +## @item "spline" +## Cubic spline interpolation---smooth first and second derivatives ## throughout the curve. ## @end table ## -## The default method is 'linear'. -## The optional return value @var{H} is a vector of handles to the surface graphic -## objects. +## The default method is @code{"linear"}. +## The optional return value @var{h} is a vector of handles to the +## surface graphic objects. ## ## Examples: ## @example -## [X,Y,Z] = meshgrid(linspace(-8,8,32)); -## V = sin (sqrt (X.^2 + Y.^2 + Z.^2)) ./ (sqrt (X.^2 + Y.^2 + Z.^2)) -## slice(X,Y,Z,V,[],0,[]) -## [XI,YI]=meshgrid(linspace(-7,7)); -## ZI=XI+YI; -## slice(X,Y,Z,V,XI,YI,ZI) +## [x, y, z] = meshgrid (linspace (-8, 8, 32)); +## v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2)); +## slice (x, y, z, v, [], 0, []); +## [xi, yi] = meshgrid (linspace (-7, 7)); +## zi = xi + yi; +## slice (x, y, z, v, xi, yi, zi); ## @end example ## @seealso{interp3, surface, pcolor} ## @end deftypefn -## Author: Kai Habel <kai.habel at gmx.de> +## Author: Kai Habel <kai.habel@gmx.de> -function h = slice(varargin) +function h = slice (varargin) method = "linear"; extrapval = NA; @@ -81,82 +81,86 @@ endif if (nargs == 4) - V = varargin{1}; - if (ndims (V) != 3) + v = varargin{1}; + if (ndims (v) != 3) error ("slice: expect 3-dimensional array of values"); endif - [nx, ny, nz] = size(V); - [X,Y,Z] = meshgrid(1:nx,1:ny,1:nz); + [nx, ny, nz] = size (v); + [x, y, z] = meshgrid (1:nx, 1:ny, 1:nz); sx = varargin{2}; sy = varargin{3}; sz = varargin{4}; elseif (nargs == 7) - V = varargin{4}; - if (ndims (V) != 3) + v = varargin{4}; + if (ndims (v) != 3) error ("slice: expect 3-dimensional array of values"); endif - X = varargin{1}; - Y = varargin{2}; - Z = varargin{3}; - if (all([isvector(X) isvector(Y) isvector(Z)])) - [X,Y,Z] = meshgrid(X,Y,Z); - elseif ((ndims(X) == 3) && size_equal(X,Y) && size_equal(X,Z)) - ##do nothing + x = varargin{1}; + y = varargin{2}; + z = varargin{3}; + if (all ([isvector(x), isvector(y), isvector(z)])) + [x, y, z] = meshgrid (x, y, z); + elseif (ndims (x) == 3 && size_equal (x, y) && size_equal (x, z)) + ## Do nothing. else - error("slice: X,Y,Z size mismatch") + error ("slice: X, Y, Z size mismatch") endif sx = varargin{5}; sy = varargin{6}; sz = varargin{7}; else - print_usage(); + print_usage (); endif - if (any([isvector(sx), isvector(sy), isvector(sz)])) - have_sval = true(); - elseif ((ndims(sx) == 2) && size_equal(sx,sy) && size_equal(sx,sz)) - have_sval = false(); + if (any ([isvector(sx), isvector(sy), isvector(sz)])) + have_sval = true; + elseif (ndims(sx) == 2 && size_equal (sx, sy) && size_equal (sx, sz)) + have_sval = false; else - error ("slice: dimensional mismatch for (XI,YI,ZI) or (sx,sy,sz)"); + error ("slice: dimensional mismatch for (XI, YI, ZI) or (SX, SY, SZ)"); endif newplot (); - ax = gca; + ax = gca (); sidx = 1; - maxv = max(V(:)); - minv = min(V(:)); - set(ax, "CLim", [minv, maxv]); + maxv = max (v(:)); + minv = min (v(:)); + set (ax, "clim", [minv, maxv]); if (have_sval) - ns = length(sx) + length(sy) + length(sz); + ns = length (sx) + length (sy) + length (sz); hs = zeros(ns,1); - [ny, nx, nz] = size(V); + [ny, nx, nz] = size (v); if (length(sz) > 0) - for i=1:length(sz) - [XI,YI,ZI] = meshgrid(squeeze(X(1,:,1)),squeeze(Y(:,1,1)),sz(i)); - Vz = squeeze(interp3(X,Y,Z,V,XI,YI,ZI,method)); - tmp(sidx++) = surface(XI,YI,sz(i)*ones(size(YI)),Vz); + for i = 1:length(sz) + [xi, yi, zi] = meshgrid (squeeze (x(1,:,1)), + squeeze (y(:,1,1)), sz(i)); + vz = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); + tmp(sidx++) = surface (xi, yi, sz(i) * ones (size (yi)), vz); endfor endif - if (length(sy) > 0) - for i=length(sy):-1:1 - [XI,YI,ZI] = meshgrid(squeeze(X(1,:,1)),sy(i),squeeze(Z(1,1,:))); - Vy = squeeze(interp3(X,Y,Z,V,XI,YI,ZI,method)); - tmp(sidx++) = surface(squeeze(XI),squeeze(sy(i)*ones(size(ZI))),squeeze(ZI),Vy); + if (length (sy) > 0) + for i = length(sy):-1:1 + [xi, yi, zi] = meshgrid (squeeze (x(1,:,1)), sy(i), squeeze (z(1,1,:))); + vy = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); + tmp(sidx++) = surface (squeeze (xi), + squeeze (sy(i) * ones (size (zi))), + squeeze (zi), vy); endfor endif - if (length(sx) > 0) - for i=length(sx):-1:1 - [XI,YI,ZI] = meshgrid(sx(i),squeeze(Y(:,1,1)),squeeze(Z(1,1,:))); - Vx = squeeze(interp3(X,Y,Z,V,XI,YI,ZI,method)); - tmp(sidx++) = surface(squeeze(sx(i)*ones(size(ZI))),squeeze(YI),squeeze(ZI),Vx); + if (length (sx) > 0) + for i = length(sx):-1:1 + [xi, yi, zi] = meshgrid (sx(i), squeeze (y(:,1,1)), squeeze (z(1,1,:))); + vx = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); + tmp(sidx++) = surface (squeeze (sx(i) * ones (size (zi))), + squeeze (yi), squeeze(zi), vx); endfor endif else - VI = interp3(X,Y,Z,V,sx,sy,sz); - tmp(sidx++) = surface(sx,sy,sz,VI); + vi = interp3 (x, y, z, v, sx, sy, sz); + tmp(sidx++) = surface (sx, sy, sz, vi); endif if (! ishold ()) @@ -167,4 +171,4 @@ h = tmp; endif -end +endfunction