File Exchange

image thumbnail

Structure display

version 1.1 (1.82 KB) by

simple recursive display of a structure content in Matlab

3.85714
15 Ratings

36 Downloads

Updated

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

z8080 (view profile)

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!

Seiki SAKAKI

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

Thomas Deneux

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

very nice for me!! thanks!

marc

marc (view profile)

Useful for me

Jeff

Jeff (view profile)

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

Simon (view profile)

simple and neat

Thomas Vanaret

Thomas Vanaret (view profile)

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

Markus Buehren

Markus Buehren (view profile)

Jeff H

Jeff H (view profile)

Quick and effective display of structs

B. Roossien

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

Updates

1.1

bux fixes

added help and array/cell display

change summary

MATLAB Release
MATLAB 7.3 (R2006b)

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

» Watch video