File Exchange

image thumbnail

Graphically display the 'branch' structure of a struct variable

version 1.0 (1.7 KB) by

Recursive function designed to display the 'branch' structure of struct variables.

13 Ratings



View License

Welcome to my first post!

Recursive function 'structstruct.m' accepts a single input of any class and outputs ASCII to the command window. Currently no function outputs.

For non-structure input, structstruct displays the class and size of the input and then exits. For structure input, structstruct displays the fields and sub-fields of the input in an ASCII graphical printout in the command window. The order of structure fields is preserved.

Has header and commented 'help' text with INPUT/OUTPUT info. Code is decently commented.

I designed this function so I could easily explore the structure of a struct variable without 'digging' through all the fields in the Variable Editor. It serves its purpose very well, but there are surely areas for expanded/improved functionality that I'm not seeing...

Comments and suggestions welcome!

Comments and Ratings (16)

Luigi Feriani

Thanks, this is great. However, the function as is will only display the size along the first two dimensions of each field. Just substituting the lines

sizestr = [int2str(sizes(1)),'x',int2str(sizes(2))];


sizestr = int2str(sizes(1));
for sc = 2:numel(sizes)
    sizestr = [sizestr,'x',int2str(sizes(sc))];

does the trick.

Luigi Feriani

Junchao Xu


Exactly what I wanted! Thanks! Great!


Ryan (view profile)

Nice tool! Thanks.

(P.s. I second Nik on the nested cell idea.)

Xiaohan Du



Nik (view profile)


Nik (view profile)

Great function, elegant implementation. Thanks.

I found it very useful and extened it in the following way:
1. To display the structure of (potentially hierarchical) cells too.
2. To display the value of terminal nodes (character or numeric).

Thanks, Andrew. I will drop you an email with my extension.

Y Simson

Y Simson (view profile)

Thanks. This is very useful.

Even more useful would be a graphical output in HTML format. How hard would it be to do to do this?

Any ideas?

Ce Gao

Ce Gao (view profile)

mostafa saeed

mostafa saeed

think's for you. great work


nan (view profile)

This works really well.

I decided I wanted to display the contents of singletons and strings, instead of their size and type, since I'm storing metadata in complex structures. That update was easy to add, a couple of lines checking the size and type. The original will also be useful when I really just want the structure itself.
Thanks for sharing this, Andrew.

MATLAB Release
MATLAB 7.11 (R2010b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video