Mercurial > hg > octave-nkf
annotate scripts/plot/slice.m @ 11587:c792872f8942
all script files: untabify and strip trailing whitespace
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:35:29 -0500 |
parents | 3c6e8aaa9555 |
children | 5ec6aa05638d |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2007-2011 Kai Habel, David Bateman |
7183 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} slice (@var{x}, @var{y}, @var{z}, @var{v}, @var{sx}, @var{sy}, @var{sz}) |
7184 | 21 ## @deftypefnx {Function File} {} slice (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}) |
22 ## @deftypefnx {Function File} {} slice (@var{v}, @var{sx}, @var{sy}, @var{sz}) | |
23 ## @deftypefnx {Function File} {} slice (@var{v}, @var{xi}, @var{yi}, @var{zi}) | |
24 ## @deftypefnx {Function File} {@var{h} =} slice (@dots{}) | |
25 ## @deftypefnx {Function File} {@var{h} =} slice (@dots{}, @var{method}) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
26 ## Plot slices of 3-D data/scalar fields. Each element of the 3-dimensional |
7184 | 27 ## array @var{v} represents a scalar value at a location given by the |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
28 ## parameters @var{x}, @var{y}, and @var{z}. The parameters @var{x}, |
7184 | 29 ## @var{x}, and @var{z} are either 3-dimensional arrays of the same size |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## as the array @var{v} in the "meshgrid" format or vectors. The |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
31 ## parameters @var{xi}, etc. respect a similar format to @var{x}, etc., |
7184 | 32 ## and they represent the points at which the array @var{vi} is |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
33 ## interpolated using interp3. The vectors @var{sx}, @var{sy}, and |
7184 | 34 ## @var{sz} contain points of orthogonal slices of the respective axes. |
7183 | 35 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
36 ## If @var{x}, @var{y}, @var{z} are omitted, they are assumed to be |
7184 | 37 ## @code{x = 1:size (@var{v}, 2)}, @code{y = 1:size (@var{v}, 1)} and |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
38 ## @code{z = 1:size (@var{v}, 3)}. |
7183 | 39 ## |
40 ## @var{Method} is one of: | |
41 ## | |
7184 | 42 ## @table @code |
43 ## @item "nearest" | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
44 ## Return the nearest neighbor. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
45 ## |
7184 | 46 ## @item "linear" |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
47 ## Linear interpolation from nearest neighbors. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
48 ## |
7184 | 49 ## @item "cubic" |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
50 ## Cubic interpolation from four nearest neighbors (not implemented yet). |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
51 ## |
7184 | 52 ## @item "spline" |
53 ## Cubic spline interpolation---smooth first and second derivatives | |
7183 | 54 ## throughout the curve. |
55 ## @end table | |
56 ## | |
7184 | 57 ## The default method is @code{"linear"}. |
58 ## The optional return value @var{h} is a vector of handles to the | |
59 ## surface graphic objects. | |
7183 | 60 ## |
61 ## Examples: | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
62 ## |
7183 | 63 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
64 ## @group |
7184 | 65 ## [x, y, z] = meshgrid (linspace (-8, 8, 32)); |
66 ## v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2)); | |
67 ## slice (x, y, z, v, [], 0, []); | |
68 ## [xi, yi] = meshgrid (linspace (-7, 7)); | |
69 ## zi = xi + yi; | |
70 ## slice (x, y, z, v, xi, yi, zi); | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
71 ## @end group |
7183 | 72 ## @end example |
73 ## @seealso{interp3, surface, pcolor} | |
74 ## @end deftypefn | |
75 | |
7184 | 76 ## Author: Kai Habel <kai.habel@gmx.de> |
7183 | 77 |
7184 | 78 function h = slice (varargin) |
7183 | 79 |
80 method = "linear"; | |
81 nargs = nargin; | |
82 | |
83 if (ischar (varargin{end})) | |
84 method = varargin{end}; | |
85 nargs -= 1; | |
86 endif | |
87 | |
88 if (nargs == 4) | |
7184 | 89 v = varargin{1}; |
90 if (ndims (v) != 3) | |
7183 | 91 error ("slice: expect 3-dimensional array of values"); |
92 endif | |
7184 | 93 [nx, ny, nz] = size (v); |
94 [x, y, z] = meshgrid (1:nx, 1:ny, 1:nz); | |
7183 | 95 sx = varargin{2}; |
96 sy = varargin{3}; | |
97 sz = varargin{4}; | |
98 elseif (nargs == 7) | |
7184 | 99 v = varargin{4}; |
100 if (ndims (v) != 3) | |
7183 | 101 error ("slice: expect 3-dimensional array of values"); |
102 endif | |
7184 | 103 x = varargin{1}; |
104 y = varargin{2}; | |
105 z = varargin{3}; | |
106 if (all ([isvector(x), isvector(y), isvector(z)])) | |
107 [x, y, z] = meshgrid (x, y, z); | |
7292 | 108 elseif (ndims (x) == 3 && size_equal (x, y, z)) |
7184 | 109 ## Do nothing. |
7183 | 110 else |
8664 | 111 error ("slice: X, Y, Z size mismatch"); |
7183 | 112 endif |
113 sx = varargin{5}; | |
114 sy = varargin{6}; | |
115 sz = varargin{7}; | |
116 else | |
7184 | 117 print_usage (); |
7183 | 118 endif |
119 | |
7184 | 120 if (any ([isvector(sx), isvector(sy), isvector(sz)])) |
121 have_sval = true; | |
7292 | 122 elseif (ndims(sx) == 2 && size_equal (sx, sy, sz)) |
7184 | 123 have_sval = false; |
7183 | 124 else |
7184 | 125 error ("slice: dimensional mismatch for (XI, YI, ZI) or (SX, SY, SZ)"); |
7183 | 126 endif |
127 | |
128 newplot (); | |
7184 | 129 ax = gca (); |
7183 | 130 sidx = 1; |
7184 | 131 maxv = max (v(:)); |
132 minv = min (v(:)); | |
133 set (ax, "clim", [minv, maxv]); | |
7183 | 134 |
135 if (have_sval) | |
7184 | 136 ns = length (sx) + length (sy) + length (sz); |
7183 | 137 hs = zeros(ns,1); |
7184 | 138 [ny, nx, nz] = size (v); |
7183 | 139 if (length(sz) > 0) |
7184 | 140 for i = 1:length(sz) |
141 [xi, yi, zi] = meshgrid (squeeze (x(1,:,1)), | |
10549 | 142 squeeze (y(:,1,1)), sz(i)); |
7184 | 143 vz = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); |
144 tmp(sidx++) = surface (xi, yi, sz(i) * ones (size (yi)), vz); | |
7183 | 145 endfor |
146 endif | |
147 | |
7184 | 148 if (length (sy) > 0) |
149 for i = length(sy):-1:1 | |
10549 | 150 [xi, yi, zi] = meshgrid (squeeze (x(1,:,1)), sy(i), squeeze (z(1,1,:))); |
7184 | 151 vy = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); |
152 tmp(sidx++) = surface (squeeze (xi), | |
10549 | 153 squeeze (sy(i) * ones (size (zi))), |
154 squeeze (zi), vy); | |
7183 | 155 endfor |
156 endif | |
157 | |
7184 | 158 if (length (sx) > 0) |
159 for i = length(sx):-1:1 | |
160 [xi, yi, zi] = meshgrid (sx(i), squeeze (y(:,1,1)), squeeze (z(1,1,:))); | |
161 vx = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); | |
162 tmp(sidx++) = surface (squeeze (sx(i) * ones (size (zi))), | |
10549 | 163 squeeze (yi), squeeze(zi), vx); |
7183 | 164 endfor |
165 endif | |
166 else | |
7184 | 167 vi = interp3 (x, y, z, v, sx, sy, sz); |
7292 | 168 tmp = surface (sx, sy, sz, vi); |
7183 | 169 endif |
170 | |
171 if (! ishold ()) | |
7292 | 172 set (ax, "view", [-37.5, 30.0], "box", "off", "xgrid", "on", |
10549 | 173 "ygrid", "on", "zgrid", "on"); |
7183 | 174 endif |
175 | |
176 if (nargout > 0) | |
177 h = tmp; | |
178 endif | |
179 | |
7184 | 180 endfunction |
7245 | 181 |
182 %!demo | |
183 %! [x, y, z] = meshgrid (linspace (-8, 8, 32)); | |
184 %! v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2)); | |
185 %! slice (x, y, z, v, [], 0, []); | |
186 %! [xi, yi] = meshgrid (linspace (-7, 7)); | |
187 %! zi = xi + yi; | |
188 %! slice (x, y, z, v, xi, yi, zi); |