Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!newsfeed.stanford.edu!postnews.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!newsfe09.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.18 (Windows/20081105)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to rename a workspace variable in a loop?
References: <f7olca$1mj$1@fred.mathworks.com> <f7om7m$dvb$1@fred.mathworks.com> <gi9c71$c2a$1@fred.mathworks.com>
In-Reply-To: <gi9c71$c2a$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 23
Message-ID: <WlX1l.5935$%z5.391@newsfe09.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe09.iad 1229472246 24.79.146.116 (Wed, 17 Dec 2008 00:04:06 UTC)
NNTP-Posting-Date: Wed, 17 Dec 2008 00:04:06 UTC
Date: Tue, 16 Dec 2008 18:04:30 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:507416


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.

-- 
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?