comparison scripts/plot/printd.m @ 16180:3e6d15a2a50b

Update stemleaf to provide new features and minor fix to printd
author Michael Godfrey <michaeldgodfrey@gmail.com>
date Sat, 02 Mar 2013 18:01:47 -0500
parents 9978c44ab12c
children ddac88d32d6a
comparison
equal deleted inserted replaced
16179:025393bef399 16180:3e6d15a2a50b
18 ## License along with Octave; see the file COPYING. If not, 18 ## License along with Octave; see the file COPYING. If not,
19 ## see <http://www.gnu.org/licenses/>. 19 ## see <http://www.gnu.org/licenses/>.
20 20
21 ## -*- texinfo -*- 21 ## -*- texinfo -*-
22 ## @deftypefn {Function File} {} printd (@var{obj}, @var{filename}) 22 ## @deftypefn {Function File} {} printd (@var{obj}, @var{filename})
23 ## @deftypefnx {Function File} {@var{out_file} =} printd (@dots{})
23 ## 24 ##
24 ## Convert any object acceptable to @code{disp} into the format 25 ## Convert any object acceptable to @code{disp} into the format
25 ## selected by the suffix of @var{filename}. 26 ## selected by the suffix of @var{filename}. If the return argument
27 ## @var{out_file} is given, the name of the created file is returned.
26 ## 28 ##
27 ## This function is intended to facilitate manipulation of the output 29 ## This function is intended to facilitate manipulation of the output
28 ## of functions such as @code{stemleaf}. 30 ## of functions such as @code{stemleaf}.
29 ## @seealso{stemleaf} 31 ## @seealso{stemleaf}
30 ## @end deftypefn 32 ## @end deftypefn
31 33
32 ## Author: Michael D. Godfrey <michaeldgodfrey@gmail.com> 34 ## Author: Michael D. Godfrey <michaeldgodfrey@gmail.com>
33 ## Description: Convert objects into other file formats. 35 ## Description: Convert objects into other file formats.
34 36
35 function printd (obj, filename) 37 function pr_out = printd (obj, filename)
36 ## Convert any object acceptable to disp() into various display formats. 38 ## Convert any object acceptable to disp() into various display formats.
37 ## obj is the input object. 39 ## obj is the input object.
38 ## filename is the output file (with required suffix). 40 ## filename is the output file (with required suffix).
39 41
40 ## Extract .suffix from filename 42 ## Extract .suffix from filename
77 error ("Unknown conversion type: %s.\nOptions are: pdf ps eps txt jpg jpeg", opt); 79 error ("Unknown conversion type: %s.\nOptions are: pdf ps eps txt jpg jpeg", opt);
78 80
79 endswitch 81 endswitch
80 fclose (pf); 82 fclose (pf);
81 delete (tempf); 83 delete (tempf);
82 printf ("%s file %s written\n", opt, filename); 84 pr_out = sprintf ("%s file %s written\n", opt, filename);
83 endfunction 85 endfunction
84 86
85 %!demo 87 %!demo
86 %! r2 = ["stem step: 10, data: unsorted.\nHinges: lo: 12, hi: 42\n";... 88 %! r2 = char (
87 %! " 1 | 22118";" 2 | 28";" 3 | 98";" 4 | 244";" 5 | 2"]; 89 %! "stem step: 10, data: unsorted.",
90 %! "Hinges: lo: 12, hi: 42" ,
91 %! " 1 | 22118" ,
92 %! " 2 | 28" ,
93 %! " 3 | 98" ,
94 %! " 4 | 244" ,
95 %! " 5 | 2" );
88 %! printd (r2, "test_p.txt"); 96 %! printd (r2, "test_p.txt");
89 %! system ("cat test_p.txt"); 97 %! system ("cat test_p.txt");
90 %! delete ("test_p.txt"); 98 %! delete ("test_p.txt");
91 99
92 %!test 100 %!test
93 %! r2 = ["stem step: 10, data: unsorted.\nHinges: lo: 12, hi: 42\n";... 101 %! r2 = char (
94 %! " 1 | 22118";" 2 | 28";" 3 | 98";" 4 | 244";" 5 | 2"]; 102 %! "stem step: 10, data: unsorted.",
103 %! "Hinges: lo: 12, hi: 42" ,
104 %! " 1 | 22118" ,
105 %! " 2 | 28" ,
106 %! " 3 | 98" ,
107 %! " 4 | 244" ,
108 %! " 5 | 2" );
95 %! printd (r2, "test_p.txt"); 109 %! printd (r2, "test_p.txt");
96 %! r4 = fileread ("test_p.txt"); 110 %! r4 = fileread ("test_p.txt");
97 %! delete ("test_p.txt"); 111 %! delete ("test_p.txt");
98 %! r2 = disp (r2); 112 %! r2 = disp (r2);
99 %! assert (r4, r2) 113 %! assert (r4, r2)