Mercurial > hg > octave-lyh
annotate scripts/plot/slice.m @ 9051:1bf0ce0930be
Grammar check TexInfo in all .m files
Cleanup documentation sources to follow a few consistent rules.
Spellcheck was NOT done. (but will be in another changeset)
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Fri, 27 Mar 2009 22:31:03 -0700 |
parents | dbd0c77e575e |
children | 923c7cb7f13f |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2007, 2009 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 -*- | |
7184 | 20 ## @deftypefn {Function File} {} slice (@var{x}, @var{y}, @var{z}, @var{v}, @var{sx}, @var{sy}, @var{sz}) |
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}) | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## Plot slices of 3D 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 |
7184 | 31 ## parameters @var{xi}, etc respect a similar format to @var{x}, etc, |
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 ## |
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 |
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. |
7184 | 45 ## @item "linear" |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
46 ## Linear interpolation from nearest neighbors. |
7184 | 47 ## @item "cubic" |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
48 ## Cubic interpolation from four nearest neighbors (not implemented yet). |
7184 | 49 ## @item "spline" |
50 ## Cubic spline interpolation---smooth first and second derivatives | |
7183 | 51 ## throughout the curve. |
52 ## @end table | |
53 ## | |
7184 | 54 ## The default method is @code{"linear"}. |
55 ## The optional return value @var{h} is a vector of handles to the | |
56 ## surface graphic objects. | |
7183 | 57 ## |
58 ## Examples: | |
59 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
60 ## @group |
7184 | 61 ## [x, y, z] = meshgrid (linspace (-8, 8, 32)); |
62 ## v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2)); | |
63 ## slice (x, y, z, v, [], 0, []); | |
64 ## [xi, yi] = meshgrid (linspace (-7, 7)); | |
65 ## zi = xi + yi; | |
66 ## 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
|
67 ## @end group |
7183 | 68 ## @end example |
69 ## @seealso{interp3, surface, pcolor} | |
70 ## @end deftypefn | |
71 | |
7184 | 72 ## Author: Kai Habel <kai.habel@gmx.de> |
7183 | 73 |
7184 | 74 function h = slice (varargin) |
7183 | 75 |
76 method = "linear"; | |
77 nargs = nargin; | |
78 | |
79 if (ischar (varargin{end})) | |
80 method = varargin{end}; | |
81 nargs -= 1; | |
82 endif | |
83 | |
84 if (nargs == 4) | |
7184 | 85 v = varargin{1}; |
86 if (ndims (v) != 3) | |
7183 | 87 error ("slice: expect 3-dimensional array of values"); |
88 endif | |
7184 | 89 [nx, ny, nz] = size (v); |
90 [x, y, z] = meshgrid (1:nx, 1:ny, 1:nz); | |
7183 | 91 sx = varargin{2}; |
92 sy = varargin{3}; | |
93 sz = varargin{4}; | |
94 elseif (nargs == 7) | |
7184 | 95 v = varargin{4}; |
96 if (ndims (v) != 3) | |
7183 | 97 error ("slice: expect 3-dimensional array of values"); |
98 endif | |
7184 | 99 x = varargin{1}; |
100 y = varargin{2}; | |
101 z = varargin{3}; | |
102 if (all ([isvector(x), isvector(y), isvector(z)])) | |
103 [x, y, z] = meshgrid (x, y, z); | |
7292 | 104 elseif (ndims (x) == 3 && size_equal (x, y, z)) |
7184 | 105 ## Do nothing. |
7183 | 106 else |
8664 | 107 error ("slice: X, Y, Z size mismatch"); |
7183 | 108 endif |
109 sx = varargin{5}; | |
110 sy = varargin{6}; | |
111 sz = varargin{7}; | |
112 else | |
7184 | 113 print_usage (); |
7183 | 114 endif |
115 | |
7184 | 116 if (any ([isvector(sx), isvector(sy), isvector(sz)])) |
117 have_sval = true; | |
7292 | 118 elseif (ndims(sx) == 2 && size_equal (sx, sy, sz)) |
7184 | 119 have_sval = false; |
7183 | 120 else |
7184 | 121 error ("slice: dimensional mismatch for (XI, YI, ZI) or (SX, SY, SZ)"); |
7183 | 122 endif |
123 | |
124 newplot (); | |
7184 | 125 ax = gca (); |
7183 | 126 sidx = 1; |
7184 | 127 maxv = max (v(:)); |
128 minv = min (v(:)); | |
129 set (ax, "clim", [minv, maxv]); | |
7183 | 130 |
131 if (have_sval) | |
7184 | 132 ns = length (sx) + length (sy) + length (sz); |
7183 | 133 hs = zeros(ns,1); |
7184 | 134 [ny, nx, nz] = size (v); |
7183 | 135 if (length(sz) > 0) |
7184 | 136 for i = 1:length(sz) |
137 [xi, yi, zi] = meshgrid (squeeze (x(1,:,1)), | |
138 squeeze (y(:,1,1)), sz(i)); | |
139 vz = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); | |
140 tmp(sidx++) = surface (xi, yi, sz(i) * ones (size (yi)), vz); | |
7183 | 141 endfor |
142 endif | |
143 | |
7184 | 144 if (length (sy) > 0) |
145 for i = length(sy):-1:1 | |
146 [xi, yi, zi] = meshgrid (squeeze (x(1,:,1)), sy(i), squeeze (z(1,1,:))); | |
147 vy = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); | |
148 tmp(sidx++) = surface (squeeze (xi), | |
149 squeeze (sy(i) * ones (size (zi))), | |
150 squeeze (zi), vy); | |
7183 | 151 endfor |
152 endif | |
153 | |
7184 | 154 if (length (sx) > 0) |
155 for i = length(sx):-1:1 | |
156 [xi, yi, zi] = meshgrid (sx(i), squeeze (y(:,1,1)), squeeze (z(1,1,:))); | |
157 vx = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); | |
158 tmp(sidx++) = surface (squeeze (sx(i) * ones (size (zi))), | |
159 squeeze (yi), squeeze(zi), vx); | |
7183 | 160 endfor |
161 endif | |
162 else | |
7184 | 163 vi = interp3 (x, y, z, v, sx, sy, sz); |
7292 | 164 tmp = surface (sx, sy, sz, vi); |
7183 | 165 endif |
166 | |
167 if (! ishold ()) | |
7292 | 168 set (ax, "view", [-37.5, 30.0], "box", "off", "xgrid", "on", |
169 "ygrid", "on", "zgrid", "on"); | |
7183 | 170 endif |
171 | |
172 if (nargout > 0) | |
173 h = tmp; | |
174 endif | |
175 | |
7184 | 176 endfunction |
7245 | 177 |
178 %!demo | |
179 %! [x, y, z] = meshgrid (linspace (-8, 8, 32)); | |
180 %! v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2)); | |
181 %! slice (x, y, z, v, [], 0, []); | |
182 %! [xi, yi] = meshgrid (linspace (-7, 7)); | |
183 %! zi = xi + yi; | |
184 %! slice (x, y, z, v, xi, yi, zi); |