Mercurial > hg > octave-nkf
annotate scripts/plot/slice.m @ 14237:11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Add clf() to all demos using plot features to get reproducibility.
Use 64 as input to all colormaps (jet (64)) to get reproducibility.
* bicubic.m, cell2mat.m, celldisp.m, cplxpair.m, interp1.m, interp2.m,
interpft.m, interpn.m, profile.m, profshow.m, convhull.m, delaunay.m,
griddata.m, inpolygon.m, voronoi.m, autumn.m, bone.m, contrast.m, cool.m,
copper.m, flag.m, gmap40.m, gray.m, hot.m, hsv.m, image.m, imshow.m, jet.m,
ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, white.m, winter.m,
condest.m, onenormest.m, axis.m, clabel.m, colorbar.m, comet.m, comet3.m,
compass.m, contour.m, contour3.m, contourf.m, cylinder.m, daspect.m,
ellipsoid.m, errorbar.m, ezcontour.m, ezcontourf.m, ezmesh.m, ezmeshc.m,
ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m, feather.m, fill.m,
fplot.m, grid.m, hold.m, isosurface.m, legend.m, loglog.m, loglogerr.m,
pareto.m, patch.m, pbaspect.m, pcolor.m, pie.m, pie3.m, plot3.m, plotmatrix.m,
plotyy.m, polar.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m,
rose.m, scatter.m, scatter3.m, semilogx.m, semilogxerr.m, semilogy.m,
semilogyerr.m, shading.m, slice.m, sombrero.m, stairs.m, stem.m, stem3.m,
subplot.m, surf.m, surfc.m, surfl.m, surfnorm.m, text.m, title.m, trimesh.m,
triplot.m, trisurf.m, uigetdir.m, uigetfile.m, uimenu.m, uiputfile.m,
waitbar.m, xlim.m, ylim.m, zlim.m, mkpp.m, pchip.m, polyaffine.m, spline.m,
bicgstab.m, cgs.m, gplot.m, pcg.m, pcr.m, treeplot.m, strtok.m, demo.m,
example.m, rundemos.m, speed.m, test.m, calendar.m, datestr.m, datetick.m,
weekday.m: Revamp %!demos to use Octave coding conventions on spacing, etc.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 20 Jan 2012 12:59:53 -0800 |
parents | 72c96de7a403 |
children | c4fa5e0b6193 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14089
diff
changeset
|
1 ## Copyright (C) 2007-2012 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 ## | |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
42 ## @table @asis |
7184 | 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"}. |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
58 ## |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
59 ## The optional return value @var{h} is a graphics handle to the created |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
60 ## surface object. |
7183 | 61 ## |
62 ## Examples: | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
63 ## |
7183 | 64 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
65 ## @group |
7184 | 66 ## [x, y, z] = meshgrid (linspace (-8, 8, 32)); |
67 ## v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2)); | |
68 ## slice (x, y, z, v, [], 0, []); | |
69 ## [xi, yi] = meshgrid (linspace (-7, 7)); | |
70 ## zi = xi + yi; | |
71 ## 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
|
72 ## @end group |
7183 | 73 ## @end example |
74 ## @seealso{interp3, surface, pcolor} | |
75 ## @end deftypefn | |
76 | |
7184 | 77 ## Author: Kai Habel <kai.habel@gmx.de> |
7183 | 78 |
7184 | 79 function h = slice (varargin) |
7183 | 80 |
81 method = "linear"; | |
82 nargs = nargin; | |
83 | |
84 if (ischar (varargin{end})) | |
85 method = varargin{end}; | |
86 nargs -= 1; | |
87 endif | |
88 | |
89 if (nargs == 4) | |
7184 | 90 v = varargin{1}; |
91 if (ndims (v) != 3) | |
7183 | 92 error ("slice: expect 3-dimensional array of values"); |
93 endif | |
7184 | 94 [nx, ny, nz] = size (v); |
95 [x, y, z] = meshgrid (1:nx, 1:ny, 1:nz); | |
7183 | 96 sx = varargin{2}; |
97 sy = varargin{3}; | |
98 sz = varargin{4}; | |
99 elseif (nargs == 7) | |
7184 | 100 v = varargin{4}; |
101 if (ndims (v) != 3) | |
7183 | 102 error ("slice: expect 3-dimensional array of values"); |
103 endif | |
7184 | 104 x = varargin{1}; |
105 y = varargin{2}; | |
106 z = varargin{3}; | |
107 if (all ([isvector(x), isvector(y), isvector(z)])) | |
108 [x, y, z] = meshgrid (x, y, z); | |
7292 | 109 elseif (ndims (x) == 3 && size_equal (x, y, z)) |
7184 | 110 ## Do nothing. |
7183 | 111 else |
8664 | 112 error ("slice: X, Y, Z size mismatch"); |
7183 | 113 endif |
114 sx = varargin{5}; | |
115 sy = varargin{6}; | |
116 sz = varargin{7}; | |
117 else | |
7184 | 118 print_usage (); |
7183 | 119 endif |
120 | |
7184 | 121 if (any ([isvector(sx), isvector(sy), isvector(sz)])) |
122 have_sval = true; | |
7292 | 123 elseif (ndims(sx) == 2 && size_equal (sx, sy, sz)) |
7184 | 124 have_sval = false; |
7183 | 125 else |
7184 | 126 error ("slice: dimensional mismatch for (XI, YI, ZI) or (SX, SY, SZ)"); |
7183 | 127 endif |
128 | |
129 newplot (); | |
7184 | 130 ax = gca (); |
7183 | 131 sidx = 1; |
7184 | 132 maxv = max (v(:)); |
133 minv = min (v(:)); | |
134 set (ax, "clim", [minv, maxv]); | |
7183 | 135 |
136 if (have_sval) | |
7184 | 137 ns = length (sx) + length (sy) + length (sz); |
7183 | 138 hs = zeros(ns,1); |
7184 | 139 [ny, nx, nz] = size (v); |
7183 | 140 if (length(sz) > 0) |
7184 | 141 for i = 1:length(sz) |
142 [xi, yi, zi] = meshgrid (squeeze (x(1,:,1)), | |
10549 | 143 squeeze (y(:,1,1)), sz(i)); |
7184 | 144 vz = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); |
145 tmp(sidx++) = surface (xi, yi, sz(i) * ones (size (yi)), vz); | |
7183 | 146 endfor |
147 endif | |
148 | |
7184 | 149 if (length (sy) > 0) |
150 for i = length(sy):-1:1 | |
10549 | 151 [xi, yi, zi] = meshgrid (squeeze (x(1,:,1)), sy(i), squeeze (z(1,1,:))); |
7184 | 152 vy = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); |
153 tmp(sidx++) = surface (squeeze (xi), | |
10549 | 154 squeeze (sy(i) * ones (size (zi))), |
155 squeeze (zi), vy); | |
7183 | 156 endfor |
157 endif | |
158 | |
7184 | 159 if (length (sx) > 0) |
160 for i = length(sx):-1:1 | |
161 [xi, yi, zi] = meshgrid (sx(i), squeeze (y(:,1,1)), squeeze (z(1,1,:))); | |
162 vx = squeeze (interp3 (x, y, z, v, xi, yi, zi, method)); | |
163 tmp(sidx++) = surface (squeeze (sx(i) * ones (size (zi))), | |
10549 | 164 squeeze (yi), squeeze(zi), vx); |
7183 | 165 endfor |
166 endif | |
167 else | |
7184 | 168 vi = interp3 (x, y, z, v, sx, sy, sz); |
7292 | 169 tmp = surface (sx, sy, sz, vi); |
7183 | 170 endif |
171 | |
172 if (! ishold ()) | |
7292 | 173 set (ax, "view", [-37.5, 30.0], "box", "off", "xgrid", "on", |
10549 | 174 "ygrid", "on", "zgrid", "on"); |
7183 | 175 endif |
176 | |
177 if (nargout > 0) | |
178 h = tmp; | |
179 endif | |
180 | |
7184 | 181 endfunction |
7245 | 182 |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
183 |
7245 | 184 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
185 %! clf; |
7245 | 186 %! [x, y, z] = meshgrid (linspace (-8, 8, 32)); |
187 %! v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2)); | |
188 %! slice (x, y, z, v, [], 0, []); | |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
189 |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
190 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
191 %! clf; |
14086
41511cce0488
test: Fix 2nd demo for slice() (bug #35143)
Rik <octave@nomad.inbox5.com>
parents:
14001
diff
changeset
|
192 %! [x, y, z] = meshgrid (linspace (-8, 8, 32)); |
41511cce0488
test: Fix 2nd demo for slice() (bug #35143)
Rik <octave@nomad.inbox5.com>
parents:
14001
diff
changeset
|
193 %! v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2)); |
7245 | 194 %! [xi, yi] = meshgrid (linspace (-7, 7)); |
195 %! zi = xi + yi; | |
196 %! slice (x, y, z, v, xi, yi, zi); | |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
197 |