Mercurial > octave
annotate doc/interpreter/interpimages.m @ 9912:e9fe12c1b0c0
Set default papersize to the desired imagesize
Set default paperorientation to landscape to stop warning message
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Fri, 04 Dec 2009 09:45:15 -0800 |
parents | 20ee7f9cc904 |
children | e76d8c767584 |
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) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
20 set_print_size (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
21 hide_output (); |
7257 | 22 if (strcmp (typ, "png")) |
23 set (0, "defaulttextfontname", "*"); | |
24 endif | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
25 |
7262 | 26 if (strcmp (typ, "txt")) |
27 image_as_txt (nm); | |
28 elseif (strcmp (nm, "interpft")) | |
6721 | 29 t = 0 : 0.3 : pi; dt = t(2)-t(1); |
30 n = length (t); k = 100; | |
31 ti = t(1) + [0 : k-1]*dt*n/k; | |
32 y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
33 yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1); | |
34 plot (ti, yp, 'g', ti, interp1(t, y, ti, 'spline'), 'b', ... | |
35 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
|
36 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
|
37 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6721 | 38 elseif (strcmp (nm, "interpn")) |
39 x = y = z = -1:1; | |
40 f = @(x,y,z) x.^2 - y - z.^2; | |
41 [xx, yy, zz] = meshgrid (x, y, z); | |
42 v = f (xx,yy,zz); | |
43 xi = yi = zi = -1:0.1:1; | |
44 [xxi, yyi, zzi] = ndgrid (xi, yi, zi); | |
45 vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline'); | |
6723 | 46 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
|
47 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6743 | 48 elseif (strcmp (nm, "interpderiv1")) |
49 t = -2:2; | |
50 dt = 1; | |
51 ti =-2:0.025:2; | |
52 dti = 0.025; | |
53 y = sign(t); | |
54 ys = interp1(t,y,ti,'spline'); | |
55 yp = interp1(t,y,ti,'pchip'); | |
56 plot (ti, ys,'r-', ti, yp,'g-'); | |
57 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
|
58 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6743 | 59 elseif (strcmp (nm, "interpderiv2")) |
60 t = -2:2; | |
61 dt = 1; | |
62 ti =-2:0.025:2; | |
63 dti = 0.025; | |
64 y = sign(t); | |
6721 | 65 ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti; |
66 ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti; | |
6743 | 67 plot (ti(2:end-1),ddys,'r*', ti(2:end-1),ddyp,'g+'); |
68 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
|
69 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6721 | 70 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
71 hide_output (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
72 endfunction |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
73 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
74 function set_print_size () |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
75 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
|
76 border = 0; # For postscript use 50/72 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
77 set (0, "defaultfigurepapertype", "<custom>"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
78 set (0, "defaultfigurepaperorientation", "landscape"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
79 set (0, "defaultfigurepapersize", image_size + 2*border); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
80 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
6721 | 81 endfunction |
82 | |
83 ## Use this function before plotting commands and after every call to | |
84 ## print since print() resets output to stdout (unfortunately, gnpulot | |
85 ## 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
|
86 function hide_output () |
6721 | 87 f = figure (1); |
88 set (f, "visible", "off"); | |
89 endfunction | |
7262 | 90 |
91 ## generate something for the texinfo @image command to process | |
92 function image_as_txt(nm) | |
93 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
94 fputs (fid, "\n"); | |
95 fputs (fid, "+---------------------------------+\n"); | |
96 fputs (fid, "| Image unavailable in text mode. |\n"); | |
97 fputs (fid, "+---------------------------------+\n"); | |
98 fclose (fid); | |
99 endfunction |