Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.fr>
Newsgroups: comp.soft-sys.matlab
Subject: Re: problem with a 'for' loop
Date: Sat, 5 Jul 2008 15:13:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 30
Message-ID: <g4o31t$bj$1@fred.mathworks.com>
References: <g4nse3$gco$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.fr>
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 1215270781 371 172.30.248.37 (5 Jul 2008 15:13:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 5 Jul 2008 15:13:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:477658



"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