Path: news.mathworks.com!not-for-mail
From: Loren Shure <loren@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Best way to loop through unknown structure
Date: Wed, 15 Aug 2007 15:51:08 -0400
Organization: The MathWorks
Lines: 31
Message-ID: <MPG.212d2338ef82a6059897a2@news.mathworks.com>
References: <f9ufl4$tb$1@fred.mathworks.com>
NNTP-Posting-Host: shurel.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1187207468 10989 144.212.219.159 (15 Aug 2007 19:51:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 15 Aug 2007 19:51:08 +0000 (UTC)
User-Agent: MicroPlanet-Gravity/2.70.2067
Xref: news.mathworks.com comp.soft-sys.matlab:424050


In article <f9ufl4$tb$1@fred.mathworks.com>, karltru@gmail.com says...
> 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 
> 

See this blog post today on looping through non-numeric arrays:

http://blogs.mathworks.com/loren/2007/08/15/iterating-over-non-numeric-
values/

I think you have an extra level of indexing that you can do without.

-- 
Loren
http://blogs.mathworks.com/loren/