Welcome, guest | Sign In | My Account | Store | Cart

This code, when passed a MATLAB structure, will recursively go into it and print out the form of the struct.

Python, 19 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
function diginto(thestruct, level)

if nargin < 2
    level = 0;
end

fn = fieldnames(thestruct);
for n = 1:length(fn)
    tabs = '';
    for m = 1:level
        tabs = [tabs '    '];
    end
    disp([tabs fn{n}])
    fn2 = getfield(thestruct,fn{n});
    if isstruct(fn2)
        diginto(fn2, level+1);
    end
end
end
Created by Kaushik Ghose on Fri, 5 Sep 2008 (MIT)
Python recipes (4591)
Kaushik Ghose's recipes (15)

Required Modules

  • (none specified)

Other Information and Tasks