From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: xlsread multiple xls files?
Date: Tue, 30 Oct 2012 09:24:01 -0500
Organization: NNTP Server
Lines: 53
Message-ID: <k6ontc$b52$>
References: <eed426f.-1@webx.raydaftYaTP> <eed426f.2@webx.raydaftYaTP> <k6om7t$30b$>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20120306 Thunderbird/3.1.20
X-Notice: Filtered by postfilter v. 0.8.2
Xref: comp.soft-sys.matlab:781667

On 10/30/2012 8:55 AM, Johan wrote:
> "J favreau" <> 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


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