Code covered by the BSD License

### Highlights from Stem and leaf plot

3.8
3.8 | 5 ratings Rate this file 33 Downloads (last 30 days) File Size: 2.1 KB File ID: #30217

# Stem and leaf plot

### Jered Wells (view profile)

28 Jan 2011 (Updated )

This is a simple utility for making stem and leaf plots output to the command window.

File Information
Description

Plots stem and leaf plot to command window

stemleafplot(v)
stemleafplot(v,p)

STEMLEAFPLOT plots stem-leaf plots of the input V to the command window.
Leaf precision may be defined by the user. Note that inputs will be
rounded to the nearest leaf unit (http://en.wikipedia.org/wiki/Stemplot).

INPUT
V : Array of numerical inputs (NaN values are ignored)

OPTION
P : Leaf precision (defined as integer power of 10)
Stem precision (by default) is 10^(P+1).
P is automatically rounded at the beginning of the function.
Leaf and stem units are printed at the bottom of the graph.
Examples: P = -3 rounds V to the nearest 10^-3 = 0.001
P = 3 rounds V to the nearest 10^3 = 1000
[DEFAULT: P = 0]

OUTPUT
Command window output

EXAMPLES
% Stem-leaf plot of V with unit precision
V = 10.*randn(1,50);
stemleafplot(V)

% Stem-leaf plot of V with precision of 0.1
V = randn(1,50);
stemleafplot(V,-1)

% Stem-leaf plot of V with precision of 100
V = 5000.*randn(1,50);
stemleafplot(V,2)

Jered Wells
01/28/2011
jered [dot] wells [at] duke [dot] edu

v1.2 (02/14/2012)

MATLAB release MATLAB 7.7 (R2008b)
02 Jun 2014 Edgar Guevara

### Edgar Guevara (view profile)

@Jered: ROUNDN is not a default function. It is part of the Mapping toolbox, I think if that constraint is specified on your file description, it would improve the quality of this submission.

Comment only
10 May 2013 Jered Wells

### Jered Wells (view profile)

farfan: ROUNDN is a default MATLAB function. I'm not sure when it was released, but perhaps your version of MATLAB is older than R2008b? Check out the MATLAB documentation for more details: http://www.mathworks.com/help/map/ref/roundn.html

Comment only
19 Jul 2012 farhan

### farhan (view profile)

I tried the example code but got an error.

>> V = randn(1,50);
>> stemleafplot(V,-1)
Undefined function 'roundn' for input arguments of type 'double'.

Error in stemleafplot (line 55)
v = roundn(v,p);

Does this roundn refer to this function?

http://www.mathworks.com/matlabcentral/fileexchange/37067-roundnxn-returns-x-rounded-to-n-digits

Comment only
10 May 2012 M Sohrabinia

### M Sohrabinia (view profile)

29 Nov 2011 Meatbird í

### Meatbird í (view profile)

20 May 2011 Alan Jennings

### Alan Jennings (view profile)

Does what it says. Through me for a loop until I noticed that the input had to be integers. I'd recommend that you have a rounding operation on the input, and a warning if you think it's that important. That way it avoids confusion.

To get higher precision, I'm multiplying the input by 10^3. This would be a nice second input and then mark the results by how far the decimal point is shifted.

Saved me time from trying to make one and can gives more detail then from a histogram. Seems like Stem and Leaf should be a built-in function though...

09 Feb 2011 Rob Campbell

### Rob Campbell (view profile)

John, if you're going to leave one-star ratings on someone's work then it's rude not to say why you're doing so. Jared's function does what it says and it has a help section (although no example). It would be nice if it returned the leaf and stem units. Perhaps it's possible to code it with fewer loops, but I've not looked into that carefully.

31 Jan 2011 Jered Wells

### Jered Wells (view profile)

John, is there something that can be improved? I am open to suggestions. For the data types specified, the program has worked very well for the test data that I have used.

Comment only
29 Jan 2011 John