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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 7540
diff changeset
1 ## Copyright (C) 2007, 2008 David Bateman
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
2 ##
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
3 ## This file is part of Octave.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
4 ##
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
6 ## under the terms of the GNU General Public License as published by
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
8 ## your option) any later version.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
9 ##
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
13 ## General Public License for more details.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
14 ##
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
15 ## You should have received a copy of the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
17 ## <http://www.gnu.org/licenses/>.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 6743
diff changeset
18
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
19 function interpimages (nm, typ)
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
20 bury_output ();
7257
e8a3e3e33490 [project @ 2007-12-05 01:18:41 by jwe]
jwe
parents: 7018
diff changeset
21 if (strcmp (typ, "png"))
e8a3e3e33490 [project @ 2007-12-05 01:18:41 by jwe]
jwe
parents: 7018
diff changeset
22 set (0, "defaulttextfontname", "*");
e8a3e3e33490 [project @ 2007-12-05 01:18:41 by jwe]
jwe
parents: 7018
diff changeset
23 endif
7262
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
24 if (strcmp (typ, "txt"))
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
25 image_as_txt (nm);
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
26 elseif (strcmp (nm, "interpft"))
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
27 t = 0 : 0.3 : pi; dt = t(2)-t(1);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
28 n = length (t); k = 100;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
29 ti = t(1) + [0 : k-1]*dt*n/k;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
30 y = sin (4*t + 0.3) .* cos (3*t - 0.1);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
31 yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
32 plot (ti, yp, 'g', ti, interp1(t, y, ti, 'spline'), 'b', ...
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
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
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
36 elseif (strcmp (nm, "interpn"))
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
37 x = y = z = -1:1;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
38 f = @(x,y,z) x.^2 - y - z.^2;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
39 [xx, yy, zz] = meshgrid (x, y, z);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
40 v = f (xx,yy,zz);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
41 xi = yi = zi = -1:0.1:1;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
42 [xxi, yyi, zzi] = ndgrid (xi, yi, zi);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
43 vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline');
6723
8bfb4ff637e1 [project @ 2007-06-14 10:16:35 by dbateman]
dbateman
parents: 6721
diff changeset
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
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
46 elseif (strcmp (nm, "interpderiv1"))
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
47 t = -2:2;
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
48 dt = 1;
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
49 ti =-2:0.025:2;
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
50 dti = 0.025;
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
51 y = sign(t);
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
52 ys = interp1(t,y,ti,'spline');
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
53 yp = interp1(t,y,ti,'pchip');
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
54 plot (ti, ys,'r-', ti, yp,'g-');
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
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
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
57 elseif (strcmp (nm, "interpderiv2"))
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
58 t = -2:2;
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
59 dt = 1;
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
60 ti =-2:0.025:2;
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
61 dti = 0.025;
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
62 y = sign(t);
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
63 ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
64 ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti;
6743
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
65 plot (ti(2:end-1),ddys,'r*', ti(2:end-1),ddyp,'g+');
f11fec9c06b0 [project @ 2007-06-18 19:12:48 by dbateman]
dbateman
parents: 6723
diff changeset
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
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
68 endif
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
69 bury_output ();
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
70 endfunction
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
71
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
72 ## Use this function before plotting commands and after every call to
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
73 ## print since print() resets output to stdout (unfortunately, gnpulot
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
74 ## can't pop output as it can the terminal type).
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
75 function bury_output ()
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
76 f = figure (1);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
77 set (f, "visible", "off");
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents:
diff changeset
78 endfunction
7262
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
79
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
80 ## generate something for the texinfo @image command to process
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
81 function image_as_txt(nm)
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
82 fid = fopen (sprintf ("%s.txt", nm), "wt");
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
83 fputs (fid, "\n");
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
84 fputs (fid, "+---------------------------------+\n");
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
85 fputs (fid, "| Image unavailable in text mode. |\n");
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
86 fputs (fid, "+---------------------------------+\n");
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
87 fclose (fid);
16e61aecddc1 [project @ 2007-12-05 20:50:47 by jwe]
jwe
parents: 7257
diff changeset
88 endfunction