Path: news.mathworks.com!not-for-mail
From: "Karl Trumstedt" <karltru@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Best way to loop through unknown structure
Date: Wed, 15 Aug 2007 09:05:40 +0000 (UTC)
Organization: KTH
Lines: 18
Message-ID: <f9ufl4$tb$1@fred.mathworks.com>
Reply-To: "Karl Trumstedt" <karltru@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1187168740 939 172.30.248.37 (15 Aug 2007 09:05:40 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 15 Aug 2007 09:05:40 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1062272
Xref: news.mathworks.com comp.soft-sys.matlab:424000


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