Path: news.mathworks.com!not-for-mail
From: "Karl Trumstedt" <karltru@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Best way to loop through unknown structure
Date: Wed, 15 Aug 2007 09:27:43 +0000 (UTC)
Organization: KTH
Lines: 54
Message-ID: <f9uguf$f3t$1@fred.mathworks.com>
References: <f9ufl4$tb$1@fred.mathworks.com> <f9ugf5$9v2$1@fred.mathworks.com>
Reply-To: "Karl Trumstedt" <karltru@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1187170063 15485 172.30.248.38 (15 Aug 2007 09:27:43 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 15 Aug 2007 09:27:43 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1062272
Xref: news.mathworks.com comp.soft-sys.matlab:424002


"Titus" <titus.edelhofer@mathworks.de> wrote in message 
<f9ugf5$9v2$1@fred.mathworks.com>...
> 
> "Karl Trumstedt" <karltru@gmail.com> schrieb im 
Newsbeitrag 
> news:f9ufl4$tb$1@fred.mathworks.com...
> > Here is what I am using right now. I am wondering if 
there
> > is any other way to do it. Say that I want to convert 
each
> > structure field to one regular variable. What is the 
best
> > method do you think?
> >
> > x = struct(...)
> >
> > if isstruct(x)
> >    s = fieldnames(x);
> >    for i=1:length(s)
> >        assignin('caller', char(s(i)), x.(char(s(i)));
> >    end
> > end
> >
> > / Karl
> > Developer @ Lundin Mining AB
> > http://www.lundinmining.com/index.php
> > Developer @ Kolonn AB http://www.kolonn.se
> 
> Hi,
> the only suggestion I would have is to use a simpler call
> into the cell arrays:
>         assignin('caller', s{i}, x.(s{i}));
> but that's all. Perhaps you could tell us, why you would
> need something like that?
> 
> Titus
> 
> 

Hi,
I'm mostly just experimenting :) Always nice to have more 
matlab knowledge ;)

I also have a "few" structs with data that I would like to 
make available for the user to use in the interactive 
plotting tool. I haven't really played around with it, so 
it might be possible to use the structs to plot, making it 
unnecessary to convert the structs.

Cheers
/ Karl
Developer @ Lundin Mining AB
http://www.lundinmining.com/index.php
Developer @ Kolonn AB http://www.kolonn.se