How to use tables in older versions of Matlab? [du

2019-02-26 07:24发布

问题:

This question already has an answer here:

  • Display matrix with row and column labels 6 answers

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.

回答1:

For Matlab versions 2012 and below,

can use printmat

printmat(yourMatrix, 'yourMatrix', 'ROW1 ROW2 ROW3 ROW4 ROW5', 'COLUMN1 COLUMN2 COLUMN3 COLUMN4 COLUMN5' );

or use

dataset({yourMatrix 'COLUMN1','COLUMN2','COLUMN3','COLUMN4','COLUMN5'}, ...
                'obsnames', {'ROW1','ROW2','ROW3','ROW4','ROW5'})

with reference: Display matrix with row and column labels

For Matlab versions 2012 and greater:

Use array2table, which converts an array into a table.

Example:

A = [1 4 7; 2 5 8; 3 6 9];

T = array2table(A)

T = 

    A1    A2    A3
    __    __    __

    1     4     7 
    2     5     8 
    3     6     9 


回答2:

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 


回答3:

Hi I am not sure if thats the function you meant with table(). What I am using is:

uitable('Data', c_Output(2:end,2:end), 'ColumnName', c_Output(1,2:end),...
         'RowName', c_Output(2:end,1), 'Units', 'normalized',...
         'Position', [0.575 0.32 0.33 0.13]);

c_Output is a matrix which contains my data and row/col names. The position is counted from the bottom left corner. So Top right would be (1,1). You would have to adjust it for each graph/position manually. Don't know if there is a build in function that converts a table to a "plot"