Path: news.mathworks.com!not-for-mail
From: "Ben " <basburywvu.nospam@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Save with -struct option
Date: Wed, 12 Mar 2008 12:56:02 +0000 (UTC)
Organization: Orbital Sciences Corp
Lines: 34
Message-ID: <fr8jt2$e3r$1@fred.mathworks.com>
References: <fr8hi2$b2m$1@fred.mathworks.com> <fr8iae$ksm$1@fred.mathworks.com>
Reply-To: "Ben " <basburywvu.nospam@hotmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205326562 14459 172.30.248.35 (12 Mar 2008 12:56:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 12 Mar 2008 12:56:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 425457
Xref: news.mathworks.com comp.soft-sys.matlab:456781



> "Ben ":
> <SNIP save/load a struct
> 
> one of the solutions
> 
>      s.a='a';
>      s.b=pi;
>      s.c=magic(3);
>      fnam='foo.mat'; % <- use your file name!
>      save(fnam,'s');
>      clear s;
>      whos('-file',fnam)
>      load(fnam);
>      disp(s)
> 
> us
> 
Thanks, but not exactly what I was asking.  In my example
the -struct option would have placed a,b,and c as separate
variables in the Mat file.  They would no longer be in a
structure. 
Here is an attempt I made at making it work in 6.4 but I
hate using the eval function.

%Matlab 6.5 example assuming myMatFile.mat exists
varNames = {'names1','names2','names3','namesN'};
for i = 1:length(varNames)
   temp = rand(5,1);
   eval(sprintf('%s = temp;',varNames{i}));
   save('myMatFile.mat',varNames{i},'-append')
end