File Exchange

image thumbnail

Structure display

version 1.1.0.0 (1.82 KB) by Thomas Deneux
simple recursive display of a structure content in Matlab

7 Downloads

Updated 05 Jun 2012

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This function is very simple and recursively displays the fields and sub-fields of a Matlab structure using the built-in 'disp' function.

Comments and Ratings (17)

z8080

Am using this nice function to display all contents of a very complex struc called SPM, produced by the neuroimaging software SPM. At some point in the iteration, the following errors interrupt the function:

Error using sub2ind (line 29)
Size vector must have at least 2 elements.

Error in file_array/subsref>multifile2mat (line 153)
ind = sub2ind(sobj.dim,indx2{:});

Error in file_array/subsref>subfun (line 98)
t = multifile2mat(sobj,varargin{:});

Error in file_array/subsref (line 65)
t = subfun(sobj,args{:});

Error in fn_structdisp>rec_structdisp (line 86)
rec_structdisp([subnames{i} '(' num2str(k) ')'],a(k))

Error in fn_structdisp>rec_structdisp (line 83)
rec_structdisp(subnames{i},a)

Error in fn_structdisp>rec_structdisp (line 86)
rec_structdisp([subnames{i} '(' num2str(k) ')'],a(k))

Error in fn_structdisp>rec_structdisp (line 83)
rec_structdisp(subnames{i},a)

Error in fn_structdisp (line 28)
rec_structdisp(Xname,X)

Any idea how to edit the script so that any type of structure can be fully parsed? Thanks!

Great!! IT also shows the matrices, which was what I was looking for. Thanks!

This is awesome!

How can I submit an improvement? (I mean, I improved your code a little and would like to share)

This is awesome!

How can I submit an improvement?

John Yang

This is what I want! good job.

a mnemonic after matlab's builtin celldisp:

function varargout = structdisp (varargin)
[varargout{1:nargout}] = fn_structdisp (varargin{:});
end

Does just what I wanted

Comments from B. Roossien and Jeff have been adressed in the June 2012 version.

very nice for me!! thanks!

marc

Useful for me

Jeff

Love the concept... A couple of notes:

1) I'd recommend creating an else condition to the 'if' that starts on line 49. I'm running into a case where nsub is never initialized if you set CELLRECURSIVE to false and has an error.

2) I'd recommend changing on line 90 size(a,1)>1 to (size(a,1)>1 || size(a,2)>1) so that it can display row vectors as well although they do display a little messy.

Simon

simple and neat

Looks good

Display could be a little improved and some diplayed line could be omitted (nested nested nested nested structures....) but all fields are displayed and one can quickly know where is the field

Jeff H

Quick and effective display of structs

B. Roossien

No H1-line, no help, no comments, no array support. Too simple

Updates

1.1.0.0

bux fixes

1.0.0.0

change title

added help and array/cell display

change summary

MATLAB Release Compatibility
Created with R2006b
Compatible with any release
Platform Compatibility
Windows macOS Linux