annotate scripts/plot/draw/stemleaf.m @ 19630:0e1f5a750d00

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Jan 2015 10:24:46 -0500
parents 4f43f87b7c3e 446c46af4b42
children 4197fc428c7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
1 ## Copyright (C) 2013 Michael D. Godfrey
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
2 ##
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
3 ## This file is part of Octave.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
4 ##
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
6 ## modify it under the terms of the GNU General Public
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
7 ## License as published by the Free Software Foundation;
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
8 ## either version 3 of the License, or (at your option) any
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
9 ## later version.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
10 ##
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful,
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
12 ## but WITHOUT ANY WARRANTY; without even the implied
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
13 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
14 ## PURPOSE. See the GNU General Public License for more
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
15 ## details.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
16 ##
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
17 ## You should have received a copy of the GNU General Public
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
18 ## License along with Octave; see the file COPYING. If not,
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
19 ## see <http://www.gnu.org/licenses/>.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
20
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
21
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
22 ## -*- texinfo -*-
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
23 ## @deftypefn {Function File} {} stemleaf (@var{x}, @var{caption})
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
24 ## @deftypefnx {Function File} {} stemleaf (@var{x}, @var{caption}, @var{stem_sz})
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
25 ## @deftypefnx {Function File} {@var{plotstr} =} stemleaf (@dots{})
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
26 ## Compute and display a stem and leaf plot of the vector @var{x}.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
27 ##
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
28 ## The input @var{x} should be a vector of integers. Any non-integer values
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
29 ## will be converted to integer by @code{@var{x} = fix (@var{x})}. By default
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
30 ## each element of @var{x} will be plotted with the last digit of the element
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
31 ## as a leaf value and the remaining digits as the stem. For example, 123
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
32 ## will be plotted with the stem @samp{12} and the leaf @samp{3}. The second
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
33 ## argument, @var{caption}, should be a character array which provides a
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
34 ## description of the data. It is included as a heading for the output.
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
35 ##
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
36 ## The optional input @var{stem_sz} sets the width of each stem.
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
37 ## The stem width is determined by @code{10^(@var{stem_sz} + 1)}.
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
38 ## The default stem width is 10.
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
39 ##
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
40 ## The output of @code{stemleaf} is composed of two parts: a
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
41 ## "Fenced Letter Display," followed by the stem-and-leaf plot itself.
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
42 ## The Fenced Letter Display is described in @cite{Exploratory Data Analysis}.
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
43 ## Briefly, the entries are as shown:
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
44 ##
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
45 ## @example
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
46 ## @group
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
47 ##
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
48 ## Fenced Letter Display
16573
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
49 ## #% nx|___________________ nx = numel (x)
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
50 ## M% mi| md | mi median index, md median
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
51 ## H% hi|hl hu| hs hi lower hinge index, hl,hu hinges,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
52 ## 1 |x(1) x(nx)| hs h_spreadx(1), x(nx) first
16573
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
53 ## _______ and last data value.
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
54 ## ______|step |_______ step 1.5*h_spread
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
55 ## f|ifl ifh| inner fence, lower and higher
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
56 ## |nfl nfh| no.\ of data points within fences
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
57 ## F|ofl ofh| outer fence, lower and higher
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
58 ## |nFl nFh| no.\ of data points outside outer
dd66c5bcb21e Improve layout of help text for stemleaf
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16181
diff changeset
59 ## fences
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
60 ## @end group
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
61 ## @end example
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
62 ##
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
63 ## The stem-and-leaf plot shows on each line the stem value followed by the
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
64 ## string made up of the leaf digits. If the @var{stem_sz} is not 1 the
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
65 ## successive leaf values are separated by ",".
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
66 ##
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
67 ## With no return argument, the plot is immediately displayed. If an output
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
68 ## argument is provided, the plot is returned as an array of strings.
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
69 ##
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
70 ## The leaf digits are not sorted. If sorted leaf values are desired, use
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
71 ## @code{@var{xs} = sort (@var{x})} before calling @code{stemleaf (@var{xs})}.
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
72 ##
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
73 ## The stem and leaf plot and associated displays are described in:
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
74 ## Ch. 3, @cite{Exploratory Data Analysis} by J. W. Tukey, Addison-Wesley, 1977.
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
75 ## @seealso{hist, printd}
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
76 ## @end deftypefn
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
77
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
78 ## Author: Michael D. Godfrey <michaeldgodfrey@gmail.com>
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
79 ## Description: Compute stem and leaf plot
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
80
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
81 function plotstr = stemleaf (x, caption, stem_sz)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
82 ## Compute and display a stem and leaf plot of the vector x. The x
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
83 ## vector is converted to integer by x = fix(x). If an output argument
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
84 ## is provided, the plot is returned as an array of strings. The
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
85 ## first element is the heading followed by an element for each stem.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
86 ##
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
87 ## The default stem step is 10. If stem_sz is provided the stem
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
88 ## step is set to: 10^(stem_sz+1). The x vector should be integers.
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
89 ## It will be treated so that the last digit is the leaf value and the
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
90 ## other digits are the stems.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
91 ##
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
92 ## When we first implemented stem and leaf plots in the early 1960's
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
93 ## there was some discussion about sorting vs. leaving the leaf
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
94 ## entries in the original order in the data. We decided in favor of
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
95 ## sorting the leaves for most purposes. This is the choice
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
96 ## implemented in the SNAP/IEDA system that was written at that time.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
97 ##
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
98 ## SNAP/IEDA, and particularly its stem and leaf plotting, were further
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
99 ## developed by Hale Trotter, David Hoagland (at Princeton and MIT),
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
100 ## and others.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
101 ##
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
102 ## Tukey, in EDA, generally uses unsorted leaves. In addition, he
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
103 ## described a wide range of additional display formats. This
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
104 ## implementation does not sort the leaves, but if the x vector is
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
105 ## sorted then the leaves come out sorted. A simple display format is
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
106 ## used.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
107 ##
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
108 ## I doubt if providing other options is worthwhile. The code can
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
109 ## quite easily be modified to provide specific display results. Or,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
110 ## the returned output string can be edited. The returned output is an
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
111 ## array of strings with each row containing a line of the plot
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
112 ## preceded by the lines of header text as the first row. This
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
113 ## facilitates annotation.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
114 ##
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
115 ## Note that the code has some added complexity due to the need to
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
116 ## distinguish both + and - 0 stems. The +- stem values are essential
16087
2b994ee38b1c maint: backout accidental check-in 979ebfdd240d.
Rik <rik@octave.org>
parents: 16085
diff changeset
117 ## for all plots which span 0. After dealing with +-0 stems, the added
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
118 ## complexity of putting +- data values in the correct stem is minor,
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
119 ## but the sign of 0 leaves must be checked. And, the cases where the
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
120 ## stems start or end at +- 0 must also be considered.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
121 ##
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
122 ## The fact that IEEE floating point defines +- 0 helps make this
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
123 ## easier.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
124 ##
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
125 ## Michael D. Godfrey January 2013
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
126
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
127 ## More could be implemented for better data scaling. And, of course,
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
128 ## other options for the kinds of plots described by Tukey could be
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
129 ## provided. This may best be left to users.
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
130
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
131 if (nargin < 2 || nargin > 3)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
132 print_usage ();
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
133 endif
16085
979ebfdd240d [mq]: stemleaf
Rik <rik@octave.org>
parents: 16083
diff changeset
134
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
135 if (! isvector (x))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
136 error ("stemleaf: X must be a vector");
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
137 endif
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
138
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
139 if (isinteger (x))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
140 ## Avoid use of integers because rounding rules do not use fix():
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
141 ## Example: floor (int32 (-44)/10) == -4, floor (int32 (-46)/10) = -5 !!!
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
142 x = single (x);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
143 elseif (isfloat (x))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
144 xint = fix (x);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
145 if (any (x != xint))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
146 warning ("stemleaf: X truncated to integer values");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
147 x = xint;
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
148 endif
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
149 else
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
150 error ("stemleaf: X must be a numeric vector");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
151 endif
16087
2b994ee38b1c maint: backout accidental check-in 979ebfdd240d.
Rik <rik@octave.org>
parents: 16085
diff changeset
152
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
153 if (! ischar (caption))
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
154 error ("stemleaf: CAPTION must be a character array");
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
155 endif
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
156
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
157 if (nargin == 2)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
158 stem_step = 10;
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
159 else
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
160 if (isscalar (stem_sz) && stem_sz >= 0 && isreal (stem_sz))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
161 stem_sz = fix (stem_sz);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
162 stem_step = 10^(stem_sz+1);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
163 else
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
164 error ("stemleaf: STEM_SZ must be a real integer >= 0");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
165 endif
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
166 endif
16087
2b994ee38b1c maint: backout accidental check-in 979ebfdd240d.
Rik <rik@octave.org>
parents: 16085
diff changeset
167
2b994ee38b1c maint: backout accidental check-in 979ebfdd240d.
Rik <rik@octave.org>
parents: 16085
diff changeset
168 ## Note that IEEE 754 states that -+ 0 should compare equal. This has
2b994ee38b1c maint: backout accidental check-in 979ebfdd240d.
Rik <rik@octave.org>
parents: 16085
diff changeset
169 ## led to C sort (and therefore Octave) treating them as equal. Thus,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
170 ## sort([-1 0 -0 1]) yields [-1 0 -0 1], and sort([-1 -0 0 1])
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
171 ## yields: [-1 -0 0 1]. This means that stem-and-leaf plotting cannot
16087
2b994ee38b1c maint: backout accidental check-in 979ebfdd240d.
Rik <rik@octave.org>
parents: 16085
diff changeset
172 ## rely on sort to order the data as needed for display.
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
173 ## This also applies to min()/max() so these routines can't be relied
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
174 ## upon if the max or min is -+ 0.
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
175
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
176 ## Compute hinges and fences based on ref: EDA pgs. 33 and 44.
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
177 ## Note that these outlier estimates are meant to be "distribution free".
16087
2b994ee38b1c maint: backout accidental check-in 979ebfdd240d.
Rik <rik@octave.org>
parents: 16085
diff changeset
178
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
179 nx = numel (x);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
180 xs = sort (x); # Note that sort preserves -0
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
181 mdidx = fix ((nx + 1)/2); # median index
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
182 hlidx = fix ((mdidx + 1)/2); # lower hinge index
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
183 huidx = fix (nx + 1 - hlidx); # upper hinge index
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
184 md = xs(mdidx); # median
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
185 hl = xs(hlidx); # lower hinge
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
186 hu = xs(huidx); # upper hinge
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
187 h_spread = hu - hl; # h_spread: difference between hinges
18688
4f43f87b7c3e * stemleaf.m: Correct integer step value for new %d behavior.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 17572
diff changeset
188 step = fix(1.5*h_spread); # step: 1.5 * h_spread
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
189 i_fence_l = hl - step; # inner fences: outside hinges + step
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
190 o_fence_l = hl - 2*step; # outer fences: outside hinges + 2*step
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
191 i_fence_h = hu + step;
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
192 o_fence_h = hu + 2*step;
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
193 n_out_l = sum (x<i_fence_l) - sum (x<o_fence_l);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
194 n_out_h = sum (x>i_fence_h) - sum (x>o_fence_h);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
195 n_far_l = sum (x<o_fence_l);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
196 n_far_h = sum (x>o_fence_h);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
197
17336
b81b9d079515 Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents: 17245
diff changeset
198 ## display table similar to that on pg. 33
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
199 plot_out = sprintf (" Data: %s", caption);
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
200 plot_out = [plot_out; sprintf(" ")];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
201 plot_out = [plot_out; sprintf(" Fenced Letter Display")];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
202 plot_out = [plot_out; sprintf(" ")];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
203 plot_out = [plot_out; sprintf(" #%3d|___________________", nx)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
204 plot_out = [plot_out; sprintf(" M%3d| %5d |", mdidx, md)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
205 plot_out = [plot_out; sprintf(" H%3d|%5d %5d| %d", hlidx, hl, hu, h_spread)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
206 plot_out = [plot_out; sprintf(" 1 |%5d %5d|", xs(1), xs(nx))];
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
207 plot_out = [plot_out; sprintf(" _______")];
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
208 plot_out = [plot_out; sprintf(" ______|%5d|_______",step)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
209 plot_out = [plot_out; sprintf(" f|%5d %5d|", i_fence_l, i_fence_h)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
210 plot_out = [plot_out; sprintf(" |%5d %5d| out", n_out_l, n_out_h)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
211 plot_out = [plot_out; sprintf(" F|%5d %5g|", o_fence_l, o_fence_h)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
212 plot_out = [plot_out; sprintf(" |%5d %5d| far",n_far_l,n_far_h)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
213 plot_out = [plot_out; " "];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
214
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
215 ## Determine stem values
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
216 min_x = min (x);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
217 max_x = max (x);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
218 if (min_x > 0) # all stems > 0
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
219 stems = [fix(min(x)/stem_step) : (fix(max(x)/stem_step)+1)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
220 elseif (max_x < 0) # all stems < 0
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
221 stems = [(fix(min_x/stem_step)-1) : fix(max_x/stem_step)];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
222 elseif (min_x < 0 && max_x > 0) # range crosses 0
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
223 stems = [(fix(min_x/stem_step)-1) : -0, 0 : fix(max_x/stem_step)+1 ];
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
224 else # one endpoint is a zero which may be +0 or -0
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
225 if (min_x == 0)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
226 if (any (x == 0 & signbit (x)))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
227 min_x = -0;
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
228 else
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
229 min_x = +0;
16085
979ebfdd240d [mq]: stemleaf
Rik <rik@octave.org>
parents: 16083
diff changeset
230 endif
979ebfdd240d [mq]: stemleaf
Rik <rik@octave.org>
parents: 16083
diff changeset
231 endif
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
232 if (max_x == 0)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
233 if (any (x == 0 & ! signbit (x)))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
234 max_x = +0;
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
235 else
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
236 max_x = -0;
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
237 endif
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
238 endif
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
239 stems = [];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
240 if (signbit (min_x))
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
241 stems = [(fix(min_x/stem_step)-1) : -0];
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
242 endif
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
243 if (! signbit (max_x))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
244 stems = [stems, 0 : fix(max_x/stem_step)+1 ];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
245 endif
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
246 endif
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
247
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
248 ## Vectorized version provided by Rik Wehbring (rik@octave.org)
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
249 ## Determine leaves for each stem:
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
250 new_line = 1;
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
251 for kx = 2: numel (stems)
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
252
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
253 stem_sign = signbit (stems(kx));
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
254 if (stems(kx) <= 0)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
255 idx = ((x <= stems(kx)*stem_step) & (x > (stems(kx-1)*stem_step))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
256 & (signbit (x) == stem_sign));
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
257 xlf = abs (x(idx) - stems(kx)*stem_step);
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
258 else
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
259 idx = ((x < stems(kx)*stem_step) & (x >= (stems(kx-1)*stem_step))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
260 & (signbit (x) == stem_sign));
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
261 xlf = abs (x(idx) - stems(kx-1)*stem_step);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
262 endif
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
263 ## Convert leaves to a string
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
264 if (stem_step == 10)
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
265 lf_str = sprintf ("%d", xlf);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
266 else
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
267 lf_str = "";
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
268 if (! isempty (xlf))
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
269 lf_str = sprintf ("%d", xlf(1));
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
270 if (numel (xlf) > 1)
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
271 lf_str = [lf_str sprintf(",%d", xlf(2:end))];
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
272 endif
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
273 endif
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
274 endif
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
275
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
276 ## Set correct -0
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
277 if (stems(kx) == 0 && signbit (stems(kx)))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
278 line = sprintf (" -0 | %s", lf_str); # -0 stem.
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
279 elseif (stems(kx) < 0)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
280 line = sprintf ("%4d | %s", stems(kx), lf_str);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
281 elseif (stems(kx) > 0)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
282 line = sprintf ("%4d | %s", stems(kx-1), lf_str);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
283 else
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
284 line = "";
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
285 endif
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
286
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
287 if (! isempty (lf_str) || stems(kx) == 0 || stems(kx-1) == 0)
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
288 plot_out = [plot_out; line];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
289 new_line = 1;
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
290 else
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
291 if (new_line == 1)
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
292 plot_out = [plot_out; " :"]; # just print one : if no leaves
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
293 new_line = 0;
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
294 endif
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
295 endif
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
296
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
297 endfor # kx = 2: numel (stems)
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
298
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
299 if (nargout == 0)
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
300 disp (plot_out);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
301 else
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
302 plotstr = plot_out;
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
303 endif
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
304
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
305 endfunction
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
306
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
307
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
308 %!demo
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
309 %! %% Unsorted plot:
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
310 %! x = [-22 12 -28 52 39 -2 12 10 11 11 42 38 44 18 44];
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
311 %! stemleaf (x, 'Unsorted plot');
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
312
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
313 %!demo
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
314 %! %% Sorted leaves:
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
315 %! x = [-22 12 -28 52 39 -2 12 10 11 11 42 38 44 18 44];
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
316 %! y = sort (x);
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
317 %! stemleaf (y, 'Sorted leaves');
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
318
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
319 %!demo
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
320 %! %% Sorted leaves (large dataset):
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
321 %! x = [-22 12 -28 52 39 -2 12 10 11 11 42 38 44 18 44 37 113 124 37 48 ...
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
322 %! 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 ...
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
323 %! 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 ...
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
324 %! 121 58 114 126 53 114 96 25 109 7 31 141 46 -13 71 43 117 116 27 7 ...
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
325 %! 68 40 31 115 124 42 128 52 71 118 117 38 27 106 33 117 116 111 40 ...
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
326 %! 119 47 105 57 122 109 124 115 43 120 43 27 27 18 28 48 125 107 114 ...
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
327 %! 34 133 45 120 30 127 31 116 146 21 23 30 10 20 21 30 0 100 110 1 20 ...
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
328 %! 0];
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
329 %! y = sort (x);
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
330 %! stemleaf (y, 'Sorted leaves (large dataset)');
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
331
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
332 %!demo
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
333 %! %% Gaussian leaves:
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
334 %! x = fix (30 * randn (300,1));
17026
be52288f827b Tweak some plotting demos for messages and spelling.
Rik <rik@octave.org>
parents: 16828
diff changeset
335 %! stemleaf (x, 'Gaussian leaves');
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
336
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
337 %!test
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
338 %! ## test minus to plus
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17026
diff changeset
339 %! x = [-22 12 -28 52 39 -2 12 10 11 11 42 38 44 18 44 37 113 124 37 48 127 ...
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17026
diff changeset
340 %! 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 ...
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17026
diff changeset
341 %! 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 ...
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17026
diff changeset
342 %! 114 126 53 114 96 25 109 7 31 141 46 -13 71 43 117 116 27 7 68 40 31 ...
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17026
diff changeset
343 %! 115 124 42 128 52 71 118 117 38 27 106 33 117 116 111 40 119 47 105 57 ...
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17026
diff changeset
344 %! 122 109 124 115 43 120 43 27 27 18 28 48 125 107 114 34 133 45 120 30 ...
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
345 %! 127 31 116 146 21 23 30 10 20 21 30 0 100 110 1 20 0];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
346 %! x = sort (x);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
347 %! rexp = char (
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
348 %! " Data: test minus to plus" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
349 %! " " ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
350 %! " Fenced Letter Display" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
351 %! " " ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
352 %! " #138|___________________" ,
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
353 %! " M 69| 52 |" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
354 %! " H 35| 30 116| 86" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
355 %! " 1 | -28 146|" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
356 %! " _______" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
357 %! " ______| 129|_______" ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
358 %! " f| -99 245|" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
359 %! " | 0 0| out" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
360 %! " F| -228 374|" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
361 %! " | 0 0| far" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
362 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
363 %! " -2 | 82" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
364 %! " -1 | 3" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
365 %! " -0 | 2" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
366 %! " 0 | 00177" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
367 %! " 1 | 00112288" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
368 %! " 2 | 001133577777899" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
369 %! " 3 | 000111123456777889" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
370 %! " 4 | 00122233344456788" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
371 %! " 5 | 223788" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
372 %! " 6 | 138" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
373 %! " 7 | 11" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
374 %! " : " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
375 %! " 9 | 69" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
376 %! " 10 | 04555567999" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
377 %! " 11 | 0133344455566667777899" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
378 %! " 12 | 0011223444555677788" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
379 %! " 13 | 1239" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
380 %! " 14 | 16" );
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
381 %! r = stemleaf (x, "test minus to plus", 0);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
382 %! assert (r, rexp);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
383
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
384 %!test
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
385 %! ## positive values above 0
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
386 %! x = [5 22 12 28 52 39 12 11 11 42 38 44 18 44];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
387 %! rexp = char (
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
388 %! " Data: positive values above 0",
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
389 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
390 %! " Fenced Letter Display" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
391 %! " " ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
392 %! " # 14|___________________" ,
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
393 %! " M 7| 22 |" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
394 %! " H 4| 12 42| 30" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
395 %! " 1 | 5 52|" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
396 %! " _______" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
397 %! " ______| 45|_______" ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
398 %! " f| -33 87|" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
399 %! " | 0 0| out" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
400 %! " F| -78 132|" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
401 %! " | 0 0| far" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
402 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
403 %! " 0 | 5" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
404 %! " 1 | 22118" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
405 %! " 2 | 28" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
406 %! " 3 | 98" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
407 %! " 4 | 244" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
408 %! " 5 | 2" );
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
409 %! r = stemleaf (x, "positive values above 0");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
410 %! assert (r, rexp);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
411
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
412 %!test
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
413 %! ## negative values below 0
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
414 %! x = [5 22 12 28 52 39 12 11 11 42 38 44 18 44];
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
415 %! x = -x;
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
416 %! rexp = char (
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
417 %! " Data: negative values below 0",
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
418 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
419 %! " Fenced Letter Display" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
420 %! " " ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
421 %! " # 14|___________________" ,
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
422 %! " M 7| -28 |" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
423 %! " H 4| -42 -12| 30" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
424 %! " 1 | -52 -5|" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
425 %! " _______" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
426 %! " ______| 45|_______" ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
427 %! " f| -87 33|" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
428 %! " | 0 0| out" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
429 %! " F| -132 78|" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
430 %! " | 0 0| far" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
431 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
432 %! " -5 | 2" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
433 %! " -4 | 244" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
434 %! " -3 | 98" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
435 %! " -2 | 28" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
436 %! " -1 | 22118" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
437 %! " -0 | 5" );
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
438 %! r = stemleaf (x, "negative values below 0");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
439 %! assert (r, rexp);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
440
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
441 %!test
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
442 %! ## positive values from 0
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
443 %! x = [22 12 28 52 39 2 12 0 11 11 42 38 44 18 44];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
444 %! rexp = char (
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
445 %! " Data: positive values from 0",
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
446 %! " " ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
447 %! " Fenced Letter Display" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
448 %! " " ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
449 %! " # 15|___________________" ,
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
450 %! " M 8| 22 |" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
451 %! " H 4| 11 42| 31" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
452 %! " 1 | 0 52|" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
453 %! " _______" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
454 %! " ______| 46|_______" ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
455 %! " f| -35 88|" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
456 %! " | 0 0| out" ,
18688
4f43f87b7c3e * stemleaf.m: Correct integer step value for new %d behavior.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 17572
diff changeset
457 %! " F| -81 134|" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
458 %! " | 0 0| far" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
459 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
460 %! " 0 | 20" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
461 %! " 1 | 22118" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
462 %! " 2 | 28" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
463 %! " 3 | 98" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
464 %! " 4 | 244" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
465 %! " 5 | 2" );
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
466 %! r = stemleaf (x, "positive values from 0");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
467 %! assert (r, rexp);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
468
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
469 %!test
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
470 %! ## negative values from 0
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
471 %! x = [22 12 28 52 39 2 12 0 11 11 42 38 44 18 44];
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
472 %! x = -x;
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
473 %! rexp = char (
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
474 %! " Data: negative values from 0",
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
475 %! " " ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
476 %! " Fenced Letter Display" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
477 %! " " ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
478 %! " # 15|___________________" ,
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
479 %! " M 8| -22 |" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
480 %! " H 4| -42 -11| 31" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
481 %! " 1 | -52 0|" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
482 %! " _______" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
483 %! " ______| 46|_______" ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
484 %! " f| -88 35|" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
485 %! " | 0 0| out" ,
18688
4f43f87b7c3e * stemleaf.m: Correct integer step value for new %d behavior.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 17572
diff changeset
486 %! " F| -134 81|" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
487 %! " | 0 0| far" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
488 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
489 %! " -5 | 2" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
490 %! " -4 | 244" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
491 %! " -3 | 98" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
492 %! " -2 | 28" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
493 %! " -1 | 22118" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
494 %! " -0 | 20" );
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
495 %! r = stemleaf (x, "negative values from 0");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
496 %! assert (r, rexp);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
497
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
498 %!test
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
499 %! ## both +0 and -0 present
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
500 %! x = [-9 -7 -0 0 -0];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
501 %! rexp = char (
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
502 %! " Data: both +0 and -0 present",
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
503 %! " " ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
504 %! " Fenced Letter Display" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
505 %! " " ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
506 %! " # 5|___________________" ,
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
507 %! " M 3| 0 |" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
508 %! " H 2| -7 0| 7" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
509 %! " 1 | -9 0|" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
510 %! " _______" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
511 %! " ______| 10|_______" ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
512 %! " f| -17 10|" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
513 %! " | 0 0| out" ,
18688
4f43f87b7c3e * stemleaf.m: Correct integer step value for new %d behavior.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 17572
diff changeset
514 %! " F| -27 20|" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
515 %! " | 0 0| far" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
516 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
517 %! " -0 | 9700" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
518 %! " 0 | 0" );
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
519 %! r = stemleaf (x, "both +0 and -0 present");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
520 %! assert (r, rexp);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
521
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
522 %!test
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
523 %! ## both <= 0 and -0 present
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
524 %! x = [-9 -7 0 -0];
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
525 %! rexp = char (
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
526 %! " Data: both <= 0 and -0 present",
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
527 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
528 %! " Fenced Letter Display" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
529 %! " " ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
530 %! " # 4|___________________" ,
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
531 %! " M 2| -7 |" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
532 %! " H 1| -9 0| 9" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
533 %! " 1 | -9 0|" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
534 %! " _______" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
535 %! " ______| 13|_______" ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
536 %! " f| -22 13|" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
537 %! " | 0 0| out" ,
18688
4f43f87b7c3e * stemleaf.m: Correct integer step value for new %d behavior.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 17572
diff changeset
538 %! " F| -35 26|" ,
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
539 %! " | 0 0| far" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
540 %! " " ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
541 %! " -0 | 970" ,
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
542 %! " 0 | 0" );
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
543 %! r = stemleaf (x, "both <= 0 and -0 present");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
544 %! assert (r, rexp);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
545
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
546 %!test
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
547 %! ## Example from EDA: Chevrolet Prices pg. 30
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
548 %! x = [150 250 688 695 795 795 895 895 895 ...
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16573
diff changeset
549 %! 1099 1166 1333 1499 1693 1699 1775 1995];
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
550 %! rexp = char (
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
551 %! " Data: Chevrolet Prices EDA pg.30",
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
552 %! " " ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
553 %! " Fenced Letter Display" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
554 %! " " ,
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
555 %! " # 17|___________________" ,
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
556 %! " M 9| 895 |" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
557 %! " H 5| 795 1499| 704" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
558 %! " 1 | 150 1995|" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
559 %! " _______" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
560 %! " ______| 1056|_______" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
561 %! " f| -261 2555|" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
562 %! " | 0 0| out" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
563 %! " F|-1317 3611|" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
564 %! " | 0 0| far" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
565 %! " " ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
566 %! " 1 | 50" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
567 %! " 2 | 50" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
568 %! " :" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
569 %! " 6 | 88,95" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
570 %! " 7 | 95,95" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
571 %! " 8 | 95,95,95" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
572 %! " :" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
573 %! " 10 | 99" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
574 %! " 11 | 66" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
575 %! " :" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
576 %! " 13 | 33" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
577 %! " 14 | 99" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
578 %! " :" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
579 %! " 16 | 93,99" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
580 %! " 17 | 75" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
581 %! " :" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
582 %! " 19 | 95" );
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
583 %! r = stemleaf (x, "Chevrolet Prices EDA pg.30", 1);
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
584 %! assert (r, rexp);
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
585
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
586 ## Test input validation
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
587 %!error stemleaf ()
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
588 %!error stemleaf (1, 2, 3, 4)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
589 %!error <X must be a vector> stemleaf (ones (2,2), "")
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
590 %!warning <X truncated to integer values> tmp = stemleaf ([0 0.5 1],"");
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
591 %!error <X must be a numeric vector> stemleaf ("Hello World", "data")
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
592 %!error <CAPTION must be a character array> stemleaf (1, 2)
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
593 %!error <STEM_SZ must be a real integer> stemleaf (1, "", ones (2,2))
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
594 %!error <STEM_SZ must be a real integer> stemleaf (1, "", -1)
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16087
diff changeset
595 %!error <STEM_SZ must be a real integer> stemleaf (1, "", 1+i)
16181
0f0e970723ec stemleaf.m: Use Octave coding conventions, remove unused variables.
Rik <rik@octave.org>
parents: 16180
diff changeset
596