Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Stem and leaf plot

4.0 | 6 ratings Rate this file 16 Downloads (last 30 days) File Size: 2.1 KB File ID: #30217 Version: 1.1

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.

| Watch this File

File Information

  Plots stem and leaf plot to command window
  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 (
    V : Array of numerical inputs (NaN values are ignored)
    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]
    Command window output
    % Stem-leaf plot of V with unit precision
    V = 10.*randn(1,50);
    % Stem-leaf plot of V with precision of 0.1
    V = randn(1,50);
    % Stem-leaf plot of V with precision of 100
    V = 5000.*randn(1,50);
  Jered Wells
  jered [dot] wells [at] duke [dot] edu
  v1.2 (02/14/2012)

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
28 Jul 2015 Mohamed Kurdi

Works fine

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:

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?

Comment only
10 May 2012 M Sohrabinia

M Sohrabinia (view profile)

29 Nov 2011 Meatbird í  
20 May 2011 Alan Jennings

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

John (view profile)

15 Feb 2012 1.1

Cleaned up code and help file
Included H1 line
Included examples
Added parameter to generate plot with user-defined leaf precision

Contact us