Display a struct as a table

446 views (last 30 days)
Yang on 5 Feb 2016
Hi all,
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);
We can see 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 it?
aStruct =
LocalName: {'example.cdf'}
Size: '1 KB'
ModifiedTime: '10-May-2010 21:35:00'
LocalName Size ModifiedTime
_____________ ____ ____________
'example.cdf' 1 KB [1x20 char]
  1 Comment
Matthew Eicholtz
Matthew Eicholtz on 5 Feb 2016
I'm not sure why the display ends up looking like that, but for what it's worth, it displayed ModifiedTime correctly when I added additional entries (e.g. S(2).LocalName = 'test',...).

Sign in to comment.

Accepted Answer

Steve Eddins
Steve Eddins on 5 Feb 2016
Convert the string containing the date and time into a datetime value, and then it will display better in the table.
aStruct.LocalName = {'example.cdf'};
aStruct.Size = '1 KB';
aStruct.ModifiedTime = '10-May-2010 21:35:00';
aTable = struct2table(aStruct);
aTable.ModifiedTime = datetime(aTable.ModifiedTime)
aTable =
LocalName Size ModifiedTime
_____________ ____ ____________________
'example.cdf' 1 KB 10-May-2010 21:35:00

Sign in to comment.

More Answers (1)

Andrei Ursache
Andrei Ursache on 30 Apr 2018
Using struct2table with the 'AsArray' true option produces the desired behavior:
T = struct2table(S, 'AsArray', true);


Find more on Data Type Conversion in Help Center and File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!