Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to rename a workspace variable in a loop?
Date: Wed, 17 Dec 2008 16:15:07 +0000 (UTC)
Organization: Xoran Technologies
Lines: 23
Message-ID: <gib8ib$p3p$1@fred.mathworks.com>
References: <f7olca$1mj$1@fred.mathworks.com> <f7om7m$dvb$1@fred.mathworks.com> <gi9c71$c2a$1@fred.mathworks.com> <WlX1l.5935$%z5.391@newsfe09.iad>
Reply-To: <HIDDEN>
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 1229530507 25721 172.30.248.35 (17 Dec 2008 16:15:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 17 Dec 2008 16:15:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:507551


Walter Roberson <roberson@hushmail.com> wrote in message <WlX1l.5935$%z5.391@newsfe09.iad>...
> Matt wrote:
>  
> > I''m in a situation where it would be really great to be able to save a large array X to a .mat
> > file but later to load back only pieces of X into the workspace. Imagine for instance that X
> > is a large 3D image and later you want to load in one slice at a time for some sort of
> > slice-wise processing.
> 
> > Unfortunately, load() doesn't let you do this. So, the only alternative I can come up with
> > is to save each slice of X to the .mat file as an individual variable, dynamically
> > created using eval().
> 
> Nope.
> 
> S = cell2struct(mat2cell(X,size(X,1),size(X,2),ones(1,size(X,3))),num2str((1:size(X,3)).','slice%d'),3);
> save(OutputFileName,'S', '-struct');
> 
> Or use dynamic field names in building up S and then use the save -struct approach.

Well, okay. If you're point was that you don't need to use eval(), then yes.

My point was more that this is an application requiring that arrays be assigned to dynamically named variables. The use of arrays, as encouraged by the FAQ, is not enough
here.