Path: news.mathworks.com!not-for-mail
From: "Francesco " <fsarnari@maths.leeds.ac.uk>
Newsgroups: comp.soft-sys.matlab
Subject: problem with a 'for' loop
Date: Sat, 5 Jul 2008 13:20:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <g4nse3$gco$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 1215264003 16792 172.30.248.35 (5 Jul 2008 13:20:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 5 Jul 2008 13:20:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 277707
Xref: news.mathworks.com comp.soft-sys.matlab:477643



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 
correctly?
Many thanks,
Francesco