5.0

5.0 | 2 ratings Rate this file 30 Downloads (last 30 days) File Size: 2.34 KB File ID: #27384
image thumbnail

disptable - Display matrix with column or row labels

by

 

27 Apr 2010 (Updated )

Displays a matrix with per-column or per-row labels.

| Watch this File

File Information
Description

Sometimes, rows or columns (or both) of a displayed matrix or vector have different meanings, and it would be nice to display them along with the matrix (instead of, say, remembering that the third row holds a given property of a set of data points). This function allows you to specify strings that are displayed for each column or row of the matrix.

Instead of specifying them using cell arrays of strings, the shorthand notation 'label 1|label 2|label 3|...' is allowed.

DISPTABLE(M, COL_STRINGS, ROW_STRINGS)
Displays matrix or vector M with per-column or per-row labels, specified in COL_STRINGS and ROW_STRINGS, respectively. These can be cell arrays of strings, or strings delimited by the pipe character (|).
Either COL_STRINGS or ROW_STRINGS can be ommitted or empty.

DISPTABLE(M, COL_STRINGS, ROW_STRINGS, FMT, SPACES)
FMT is an optional format string or number of significant digits, as used in NUM2STR. It can also be the string 'int', as a shorthand to specify that the values should be displayed as integers.
SPACES is an optional number of spaces to separate columns, which defaults to 1.

Example:
disptable(magic(3)*10-30, 'A|B|C', 'a|b|c')
(See screenshot above.)

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 (4)
12 Jun 2013 Jerry Gregoire

Very nice. Quick easy. saves much fprintf format hassle. Thanks

24 Sep 2012 Monica He

Thank you!

12 Feb 2012 Joao Henriques

I'm glad you found it useful! It certainly makes console output much more appealing, that's why I shared it :)

I think what you mean in your example code is:
>>disptable(exmplematrix,S,'A|B|C|D')

Notice that S is a variable, not a string.

But you're right, there's a small bug with cell arrays. I should have tested that case better. I'm updating the file, but if you don't want to wait, it's simple: just replace iscellarray with iscellstr (it appears 2 times in the file). That's all!

11 Feb 2012 Don Isiko

Hi there ^^, just wanted to say thank you very much for this submission! It really helped make my user interface for my project softer on the eyes haha. I was just wondering however, could you also give an example of using as part of the input? I tried the following but matlab wouldn't allow it...

>>disptable(exmplematrix,'S','A|B|C|D')

Where S is a string matrix defined like so:

S={'D1' 'D2 'D3' 'D4'}
S= 'D1' 'D2' 'D3' 'D4'

But whenever I try it says:

??? Undefined function or method 'iscellarray' for input arguments of type 'cell'.

Any help available with this? I'm doing this because I want to make a string that adjust its size depending upon results i.e

Bounce 1 Bounce 2 Bounce 3

Becomes:

Bounce 1 Bounce 2

When there are only results for 2 bounces because of initial values

Thanks!!

Updates
12 Feb 2012

Corrected small bug when passing cell arrays; changed default spacing to 2 spaces.

Contact us