Mercurial > octave
annotate doc/interpreter/interpimages.m @ 9298:20ee7f9cc904
Correct bugs in plot images produced for documentation
Initialized random number generator so hist plot is reproducible.
Fixed errorbar plot where errorbars were not centered on data.
Corrected typo in legend of interpft.
2009-06-03 Rik <rdrider0-list@yahoo.com>
* interpreter/plotimages.m: Correct errorbar plot for docs. Make hist plot
reprodroducible for docs.
* interpreter/interpimages.m: Correct typo in legend of interpft plot for
docs
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Wed, 03 Jun 2009 11:12:51 -0700 |
parents | eb63fbe60fab |
children | e9fe12c1b0c0 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2007, 2008 David Bateman |
7018 | 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 | |
6721 | 19 function interpimages (nm, typ) |
20 bury_output (); | |
7257 | 21 if (strcmp (typ, "png")) |
22 set (0, "defaulttextfontname", "*"); | |
23 endif | |
7262 | 24 if (strcmp (typ, "txt")) |
25 image_as_txt (nm); | |
26 elseif (strcmp (nm, "interpft")) | |
6721 | 27 t = 0 : 0.3 : pi; dt = t(2)-t(1); |
28 n = length (t); k = 100; | |
29 ti = t(1) + [0 : k-1]*dt*n/k; | |
30 y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
31 yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1); | |
32 plot (ti, yp, 'g', ti, interp1(t, y, ti, 'spline'), 'b', ... | |
33 ti, interpft (y, k), 'c', t, y, 'r+'); | |
9298
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
34 legend ('sin(4t+0.3)cos(3t-0.1)','spline','interpft','data'); |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
35 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6721 | 36 elseif (strcmp (nm, "interpn")) |
37 x = y = z = -1:1; | |
38 f = @(x,y,z) x.^2 - y - z.^2; | |
39 [xx, yy, zz] = meshgrid (x, y, z); | |
40 v = f (xx,yy,zz); | |
41 xi = yi = zi = -1:0.1:1; | |
42 [xxi, yyi, zzi] = ndgrid (xi, yi, zi); | |
43 vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline'); | |
6723 | 44 mesh (zi, yi, squeeze (vi(1,:,:))); |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
45 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6743 | 46 elseif (strcmp (nm, "interpderiv1")) |
47 t = -2:2; | |
48 dt = 1; | |
49 ti =-2:0.025:2; | |
50 dti = 0.025; | |
51 y = sign(t); | |
52 ys = interp1(t,y,ti,'spline'); | |
53 yp = interp1(t,y,ti,'pchip'); | |
54 plot (ti, ys,'r-', ti, yp,'g-'); | |
55 legend('spline','pchip', 4); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
56 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6743 | 57 elseif (strcmp (nm, "interpderiv2")) |
58 t = -2:2; | |
59 dt = 1; | |
60 ti =-2:0.025:2; | |
61 dti = 0.025; | |
62 y = sign(t); | |
6721 | 63 ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti; |
64 ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti; | |
6743 | 65 plot (ti(2:end-1),ddys,'r*', ti(2:end-1),ddyp,'g+'); |
66 legend('spline','pchip'); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
67 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6721 | 68 endif |
69 bury_output (); | |
70 endfunction | |
71 | |
72 ## Use this function before plotting commands and after every call to | |
73 ## print since print() resets output to stdout (unfortunately, gnpulot | |
74 ## can't pop output as it can the terminal type). | |
75 function bury_output () | |
76 f = figure (1); | |
77 set (f, "visible", "off"); | |
78 endfunction | |
7262 | 79 |
80 ## generate something for the texinfo @image command to process | |
81 function image_as_txt(nm) | |
82 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
83 fputs (fid, "\n"); | |
84 fputs (fid, "+---------------------------------+\n"); | |
85 fputs (fid, "| Image unavailable in text mode. |\n"); | |
86 fputs (fid, "+---------------------------------+\n"); | |
87 fclose (fid); | |
88 endfunction |