How to use tables in older versions of Matlab?

Ruwangi picture Ruwangi · Aug 20, 2014 · Viewed 9.5k times · Source

Is there any function in MATLAB 2010 or below versions to print a result (eg: Some matrices) in tabular form? All I got from googling was a table() function that works only in MATLAB 2013 or above versions. I've got MATLAB 2010 in my machine and it's not practical to download a newer version as it is very large and I'm in a hurry. Thank you.

Answer

sclarke81 picture sclarke81 · Aug 20, 2014

How about using displaytable from Matlab File Exchange: http://www.mathworks.co.uk/matlabcentral/fileexchange/33717-display-formatted-text-table-of-data

Here's an example lifted from the documentation:

Example 1 - Basic usage

colheadings = {'number of projects','sales','profit'};
rowheadings = {'Jimmy Slick', 'Norman Noob'}
data = [3 rand(1) rand(1); 1 rand(1) rand(1)];

To format the first number in each row as a decimal (%d), the second number %16.4f, and the third as %16.5E do the following:

wid = 16;
fms = {'d','.4f','.5E'};

In this case 16 will be the field width, and '.5E' is what to use for the fms argument

fileID = 1;

displaytable(data,colheadings,wid,fms,rowheadings,fileID);

This is the formatted output:

            |number of projec |           sales |          profit 
Jimmy Slick |               3 |          0.4502 |    5.22908E-001 
Norman Noob |               1 |          0.9972 |    2.78606E-002