2

I've got a problem with my table output in Matlab. I'm sure it's a minor thing but google didn't have any answer for me, neither did the Matlab help.

As soon as the vector size of a variable is bigger than 3, the output will not display the actual value. Using the Matlab help example, this is what happens:

Elements in variable BloodPressue = 3, output for table T produces: T =

            Age    Height    Weight      **BloodPressure**  
            ___    ______    ______    _________________

Smith       38     71        176       124     93      1
Johnson     43     69        163       109     77      1
Williams    38     64        131       125     83      1
Jones       40     67        133       117     75      1
Brown       49     64        119       122     80      1

Elements in variable BloodPressue = 4 (or bigger), output for table T produces: T =

            Age    Height    Weight    **BloodPressure**
            ___    ______    ______    _____________

Smith       38     71        176       [1x4 double] 
Johnson     43     69        163       [1x4 double] 
Williams    38     64        131       [1x4 double] 
Jones       40     67        133       [1x4 double] 
Brown       49     64        119       [1x4 double] 

How can I see the values for BloodPressure inside the table in the Matlab workspace?

Hoping to get some help on this?

Many thanks!

bayleaf
  • 21
  • 2

3 Answers3

1

You can use the variable viewer.

Example:

A = table(magic(5))

A = 

    Var1    
____________

[1x5 double]
[1x5 double]
[1x5 double]
[1x5 double]
[1x5 double]

In the workspace you can now double click on A:

screenshot1

This will open the following viewer which shows you the contents of the table:

screenshot2

m.s.
  • 16,063
  • 7
  • 53
  • 88
0

If your question is only about viewing the data while your working with it, the above answer will help you. Should you want to manipulate the actual output, i.e. the appearance of your table when it is being printed etc., have a look at this link:

http://www.mathworks.com/help/matlab/ref/uitable-properties.html

So, you could try making the column header broader or adjusting the width of the column in general to match your data.

Franz Wurst
  • 319
  • 2
  • 15
  • I'm using the table to summarise inputs and outputs of optimisation problems. Therefor I find the table format quite useful. – bayleaf May 10 '15 at 13:26
  • I don't think the problem is the column width as there would be no problem todisplay 3 blood pressure values, each at a single length of say 9, e.g. 123456789 123456789 123456789 - and it would all go in the column BloodPressure. Only adding a fourth (or more) element to the column BloodPressure will give me the output [1x4 double] – bayleaf May 10 '15 at 13:30
  • Hm, I can't test the output for longer values right now because MATLAB is on the other computer, so I'll have a look at it later. But what are you trying to achieve? If it's really just about seeing the content of your variable in the workspace, then m.s.' answer is all you need. – Franz Wurst May 10 '15 at 13:52
  • It;s about comparing the values, say you've got different starting conditions and numbers of iterations and optimal value in one table (so that I can compare them in one go). – bayleaf May 10 '15 at 13:56
  • @bayleaf Okay, I can't reproduce your table because I only have R2012b and it was introduced in R2013b..., but this link might help you: http://blogs.mathworks.com/loren/2013/09/10/introduction-to-the-new-matlab-data-types-in-r2013b/ By accessing the different properties your table has and displaying those you should be able to see your full entry, no matter how many there are. Hope this helps. – Franz Wurst May 11 '15 at 06:22
0

In my case I solved my problem when I found a hack:

Given array:

num2str(Comp_Matrix(3,:)','%12.10f')

ans =

0.1297092395
0.1507424182
0.1586286637
0.1587259832
0.2880978647
0.4785836471
0.4786843575
0.8680238040

Using table I got:

table(num2str(Comp_Matrix(3,:)','%12.10f'))

ans = 

       Var1    
    ___________

    [1x12 char]
    [1x12 char]
    [1x12 char]
    [1x12 char]
    [1x12 char]
    [1x12 char]
    [1x12 char]
    [1x12 char]

Well, you see that's a problem. Of course I can call table(Comp_Matrix(3,:)') - it will display actual numbers, but I need to format output! So I tried a lot of things and when I used cellstr the magic happened:

table(cellstr(num2str(Comp_Matrix(3,:)','%12.10f')))

ans = 

         Var1     
    ______________

    '0.1297092395'
    '0.1507424182'
    '0.1586286637'
    '0.1587259832'
    '0.2880978647'
    '0.4785836471'
    '0.4786843575'
    '0.8680238040'

It is still not pretty, but it is readable at least. Also you can assign column to table in that way:

TheTable = table();
TheTable.Hack =  cellstr(num2str([1 2 3 5; 4 5 6 5],'%1.2f '))

            Hack         
    _____________________

    '1.00 2.00 3.00 5.00'
    '4.00 5.00 6.00 5.00'

If somebody knows a way to display long numbers without '' quotes - plz let us know too!

Arkemlar
  • 380
  • 4
  • 12