help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to extract all variables from a structure


From: Terry Duell
Subject: Re: How to extract all variables from a structure
Date: Sat, 30 Mar 2013 09:14:00 +1100
User-agent: Opera Mail/12.14 (Linux)

On Fri, 29 Mar 2013 20:54:12 +1100, Andy Buckle <address@hidden> wrote:

[snip]

This might be modified to do something useful. Not sure I understand the
problem.
call it with
structprint(s)
and get
[data]
    [w1]
        s =  237.60
    [w2]
        s =  44.200
    [w3]
        s =  150
    [w4]
        s =  3000
    [r1]
        s =  14.500
    [r2]
        s =  14.500
-----------------------------
function structprint (s,depth)
  if 1==nargin
    depth=0;
  end
  if isstruct(s)
    fnames=fieldnames(s);
    for i=1:length(fnames)
      printf("%s[%s]\n",repmat('  ',1,depth*2),fnames{i});
      structprint(getfield(s,fnames{i}),depth+1);
    end
  else
    printf("%s",repmat('  ',1,depth*2));
    s
  end
end
-----------------------------


Carlo has come with what appears to me to be a very nice way of doing it.

Thanks for your help.

Cheers,
--
Regards,
Terry Duell


reply via email to

[Prev in Thread] Current Thread [Next in Thread]