Mercurial > hg > octave-lyh
annotate doc/interpreter/interpimages.m @ 17489:0ad2f93fd83c
doc: Fix a typo in findobj docstring.
* scripts/plot/findobj.m: Use '3' instead of 'D' in findobj example of depth 3.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 25 Sep 2013 08:13:30 -0700 |
parents | 333243133364 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11576
diff
changeset
|
1 ## Copyright (C) 2007-2012 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) |
11576
8ac9687dbe9f
rename backend to graphics_toolkit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
20 graphics_toolkit ("gnuplot"); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
21 set_print_size (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
22 hide_output (); |
7257 | 23 if (strcmp (typ, "png")) |
24 set (0, "defaulttextfontname", "*"); | |
25 endif | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
26 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
27 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
28 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
29 d_typ = ["-d", typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
30 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
31 |
7262 | 32 if (strcmp (typ, "txt")) |
33 image_as_txt (nm); | |
34 elseif (strcmp (nm, "interpft")) | |
6721 | 35 t = 0 : 0.3 : pi; dt = t(2)-t(1); |
36 n = length (t); k = 100; | |
37 ti = t(1) + [0 : k-1]*dt*n/k; | |
38 y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
39 yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1); | |
40 plot (ti, yp, 'g', ti, interp1(t, y, ti, 'spline'), 'b', ... | |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
41 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
|
42 legend ('sin(4t+0.3)cos(3t-0.1)','spline','interpft','data'); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
43 print ([nm "." typ], d_typ); |
6721 | 44 elseif (strcmp (nm, "interpn")) |
45 x = y = z = -1:1; | |
46 f = @(x,y,z) x.^2 - y - z.^2; | |
47 [xx, yy, zz] = meshgrid (x, y, z); | |
48 v = f (xx,yy,zz); | |
49 xi = yi = zi = -1:0.1:1; | |
50 [xxi, yyi, zzi] = ndgrid (xi, yi, zi); | |
51 vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline'); | |
6723 | 52 mesh (zi, yi, squeeze (vi(1,:,:))); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
53 print ([nm "." typ], d_typ); |
6743 | 54 elseif (strcmp (nm, "interpderiv1")) |
55 t = -2:2; | |
56 dt = 1; | |
57 ti =-2:0.025:2; | |
58 dti = 0.025; | |
59 y = sign(t); | |
60 ys = interp1(t,y,ti,'spline'); | |
61 yp = interp1(t,y,ti,'pchip'); | |
62 plot (ti, ys,'r-', ti, yp,'g-'); | |
63 legend('spline','pchip', 4); | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
64 print ([nm "." typ], d_typ); |
6743 | 65 elseif (strcmp (nm, "interpderiv2")) |
66 t = -2:2; | |
67 dt = 1; | |
68 ti =-2:0.025:2; | |
69 dti = 0.025; | |
70 y = sign(t); | |
6721 | 71 ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti; |
72 ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti; | |
6743 | 73 plot (ti(2:end-1),ddys,'r*', ti(2:end-1),ddyp,'g+'); |
74 legend('spline','pchip'); | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
75 print ([nm "." typ], d_typ); |
6721 | 76 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
77 hide_output (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
78 endfunction |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
79 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
80 function set_print_size () |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
81 image_size = [5.0, 3.5]; # in inches, 16:9 format |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
82 border = 0; # For postscript use 50/72 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
83 set (0, "defaultfigurepapertype", "<custom>"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
84 set (0, "defaultfigurepaperorientation", "landscape"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
85 set (0, "defaultfigurepapersize", image_size + 2*border); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
86 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
6721 | 87 endfunction |
88 | |
89 ## Use this function before plotting commands and after every call to | |
90 ## print since print() resets output to stdout (unfortunately, gnpulot | |
91 ## can't pop output as it can the terminal type). | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
92 function hide_output () |
6721 | 93 f = figure (1); |
94 set (f, "visible", "off"); | |
95 endfunction | |
7262 | 96 |
97 ## generate something for the texinfo @image command to process | |
98 function image_as_txt(nm) | |
99 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
100 fputs (fid, "\n"); | |
101 fputs (fid, "+---------------------------------+\n"); | |
102 fputs (fid, "| Image unavailable in text mode. |\n"); | |
103 fputs (fid, "+---------------------------------+\n"); | |
104 fclose (fid); | |
105 endfunction |