Path: news.mathworks.com!not-for-mail
From: "Francesco " <fsarnari@maths.leeds.ac.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: problem with a 'for' loop
Date: Sat, 5 Jul 2008 20:24:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 44
Message-ID: <g4ol91$cd3$1@fred.mathworks.com>
References: <g4nse3$gco$1@fred.mathworks.com> <g4o31t$bj$1@fred.mathworks.com>
Reply-To: "Francesco " <fsarnari@maths.leeds.ac.uk>
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 1215289441 12707 172.30.248.35 (5 Jul 2008 20:24:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 5 Jul 2008 20:24:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 277707
Xref: news.mathworks.com comp.soft-sys.matlab:477685



"Bruno Luong" <b.luong@fogale.fr> wrote in message 
<g4o31t$bj$1@fred.mathworks.com>...
> "Francesco " <fsarnari@maths.leeds.ac.uk> wrote in message
> <g4nse3$gco$1@fred.mathworks.com>...
> > Hi everybody,
> > I am trying, in a for loop over the index j to 
load .mat 
> > files (data_%d.mat) from an external hard drive E:\.
> > My files are stored in the directory dir2 and I would 
like 
> > to load only variables var1 and var2 from the .mat file.
> > I am trying to use this string, but it doesn't work...
> > 
> > for j=1:N
> >     filename = num2str(j,'data_%d.mat');
> >     load(j,'E:\dir1\dir2\filename', 'var1','var2')
> > end
> > 
> > What am I doing wrong? Could you help me to write it 
> 
> 1. 'E:\dir1\dir2\filename'
>  
> MATLAB will try to look the file named 'filename' and not
> 'data_??mat'. You need to build the string of path with 
the
> variable filename
> 
> Take a look of:
> > help strings
> 
> 2. MATLAB cannot load subset of variables in MAT file
> For correct calling syntax, take a look 
> > help load
> 
> Bruno

Thanks, Bruno!
Now it works.
Francesco