Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: xlsread multiple xls files?
Date: Tue, 30 Oct 2012 09:24:01 -0500
Organization: Aioe.org NNTP Server
Lines: 53
Message-ID: <k6ontc$b52$1@speranza.aioe.org>
References: <eed426f.-1@webx.raydaftYaTP> <eed426f.2@webx.raydaftYaTP> <k6om7t$30b$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: LGjaWr6Mx0vN2lWT59OA2A.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:781667

On 10/30/2012 8:55 AM, Johan wrote:
> "J favreau" <jmfavrea@unity.ncsu.edu> wrote in message
> <eed426f.2@webx.raydaftYaTP>...
>> a. mosher wrote:
...
>> >> FileNames=dir('*.xls);
...
>> >> for i=1:length(FileNames)
>> >>   FileToLoad=FileNames(i).name;
>> >>   %this is a xls file, load it, run code and loop
>> >> end
...

> I tried something similar before, until I found this thread an hoped to
> get a solution for my problem. But it still doesn't work for me.
> When I tell matlab to search all files with endings .xlsx, I get a
> matrix with all information about my excel file, including their
> filenames.

More specifically, DIR returns a structure...

>... As you explained, I decalare a variable called FileToLoad,
> with the name of my excelfile.
> When I then try to use xlsread('FileToLoad') it doesnt work cause matlab
> can't find a file called FileToLoad.
> Thats right so far, but why doesnt matlab simply use the information
> from the variable 'FileToLoad' instead...

Well, that's because 'FileToLoad' isn't a variable but a character string...

If you really did write

FileToLoad='mydata.xlsx';

then use the variable name not a string equal to the variable name.

> Seemingly it worked for you, but I cant figure out why, so I would
> appreciate if you can help me with my problem.

Well, it worked for the poster because he used the .name field in the 
structure returned by DIR() instead of a string of that name...

Which I'd recommend you do as well--much more flexible coding style than 
hardcoding a filename into a script or function.  Or, use uigetfile() to 
select a file interactively or somesuch.

--


> Thanks
>
> Johan