susanna
susanna

Reputation: 1521

Display a Matlab struct as a table

I have a struct. I want to display the content of this struct as a table. So I use the following transformation:

 aTable = struct2table(aStruct); 
 disp(aTable);

which returns

aStruct =

   LocalName: {'example.cdf'}
        Size: '1 KB'
ModifiedTime: '10-May-2010 21:35:00'

aTable = 

  LocalName      Size    ModifiedTime
_____________    ____    ____________
'example.cdf'    1 KB    [1x20 char] 

The value of modifiedTime is not correct. I hope to display it as a value, not as an array. Can you tell me how I can do that?

Upvotes: 0

Views: 243

Answers (1)

Oleg
Oleg

Reputation: 10676

If the string is longer than 10 chars, it will display its size rather than the string itself. Cellstrings displays the string up to 143 chars and then truncates with .... This effect is inherited from an internal call to evalc(cellstr).

struct2table(struct('Char10', '1234567890', 'Char11','11234567890','Cellstring11',{{repmat('1',1,144)}}))
ans = 
      Char10        Char11                                                                         Cellstring11                                                                  
    __________    ___________    ________________________________________________________________________________________________________________________________________________
    1234567890    [1x11 char]    '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111…'

To solve your issue, once converted to table:

aTable.ModifiedTime = cellstr(aTable.ModifiedTime);

Upvotes: 2

Related Questions