From: Sean Douglas on
hello and thanks for previous help...
I am trying to run an array of string varialbes through a for loop. I have a program that is working when I pull in 2 excel files into matlab and then run them agains each other , but now i want to set the program up to pull in mulitples files into matlab and then to run the different files against each other. I am trying to do this with a for loop with string variables inside the loop.

format long
for xx= ['TSO' 'VLO']
for yy=['OXY' 'USO']

start1=20070101
upto1=20100601

[num, txt]=xlsread('yy');
tday1=txt(2:end, 1);
tday1=datestr(datenum(tday1, 'mm/dd/yyyy'), 'yyyymmdd');
tday1=str2double(cellstr(tday1));
adjcls1=num(:, end);

[num2, txt2]=xlsread('xx);
tday2=txt2(2:end, 1);
tday2=datestr(datenum(tday2, 'mm/dd/yyyy'), 'yyyymmdd');
tday2=str2double(cellstr(tday2));
adjcls2=num2(:, end);

......
i am having trouble with this and i am getting errors:

??? Error using ==> xlsread at 219
XLSREAD unable to open file A.
File C:\Users\Lin\Documents\MATLAB\A.xls not found.

Error in ==> chancointLooptest at 21
[num, txt]=xlsread(yy);


below is the relevant part of xlread at 219, so you can look for the problem
%==============================================================================
% handle requested Excel workbook filename
try
file = validpath(file,'.xls');
catch exception
err = MException('MATLAB:xlsread:FileNotFound','XLSREAD unable to open file %s.\n%s',...
file,exception.message);
throw(err); %%%% THIS IS LINE 219
end
%=====================================================

please help, thanks
From: Jan Simon on
Dear Sean,

> for xx= ['TSO' 'VLO']
> for yy=['OXY' 'USO']

Strange. Are you sure you want to get these values for xx and yy?!

> [num, txt]=xlsread('yy');

This command calls Matlab's toolbox function XLSREAD for the file 'yy'. Do you mean the variable yy?!

> ??? Error using ==> xlsread at 219
> XLSREAD unable to open file A.
> File C:\Users\Lin\Documents\MATLAB\A.xls not found.

It is not understandable from your code, why Matlab tries to open the file "A.xls".

> Error in ==> chancointLooptest at 21
> [num, txt]=xlsread(yy);

This line does not appear in the posted code!

> below is the relevant part of xlread at 219, so you can look for the problem

Do you mean "xlsread" instead of "xlread"? It is not needed to post parts of Matlab's toolbox functions.

Deeply confused, Jan
From: Matt Fig on
There are several strange things about what you post. First of all, do you understand what you are getting here?

for xx= ['TSO' 'VLO'] ,xx,end


Next, the line which is shown as the line causing the error does not appear in the code you post. Note that you have the line which causes the error identified as:

[num, txt]=xlsread(yy);

but the closest line in your code to this is:

[num, txt]=xlsread('yy');

which is not the same line.

I can see no reason why your code should pass the filename 'A' to xlsread.

What have you left out?
From: Sean Douglas on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i2n0oq$kr2$1(a)fred.mathworks.com>...
> Dear Sean,
>
> > for xx= ['TSO' 'VLO']
> > for yy=['OXY' 'USO']
>
> Strange. Are you sure you want to get these values for xx and yy?!
>
> > [num, txt]=xlsread('yy');
>
> This command calls Matlab's toolbox function XLSREAD for the file 'yy'. Do you mean the variable yy?!
>
> > ??? Error using ==> xlsread at 219
> > XLSREAD unable to open file A.
> > File C:\Users\Lin\Documents\MATLAB\A.xls not found.
>
> It is not understandable from your code, why Matlab tries to open the file "A.xls".
>
> > Error in ==> chancointLooptest at 21
> > [num, txt]=xlsread(yy);
>
> This line does not appear in the posted code!
>
> > below is the relevant part of xlread at 219, so you can look for the problem
>
> Do you mean "xlsread" instead of "xlread"? It is not needed to post parts of Matlab's toolbox functions.
>
> Deeply confused, Jan

Yes you should be confused, im really sorry to have wasted your time..
your right, I actually did call the variable yy and xx here is what me code actually looks like:

format long g
start1=20070101
upto1=20100601

for xx=['APC' 'BHI']
for yy=['ATW' 'USO']

[num, txt]=xlsread(yy); %% THIS IS LINE 21
tday1=txt(2:end, 1);
tday1=datestr(datenum(tday1, 'mm/dd/yyyy'), 'yyyymmdd');
tday1=str2double(cellstr(tday1));
adjcls1=num(:, end);

[num2, txt2]=xlsread(xx);
tday2=txt2(2:end, 1);
tday2=datestr(datenum(tday2, 'mm/dd/yyyy'), 'yyyymmdd');
tday2=str2double(cellstr(tday2));
adjcls2=num2(:, end);


this is the end of code and here is the error (i did show the correct error before):
??? Error using ==> xlsread at 219
XLSREAD unable to open file A.
File C:\Users\Lin\Documents\MATLAB\A.xls not found.

Error in ==> chancointLooptest at 21
[num, txt]=xlsread(yy);

here is my line 21:
[num, txt]=xlsread(yy)

where i ask matlab to open variable yy, which i think the yy variable should indicate file 'ATW' , it seems maybe matlab is only reading the first letter 'A' for some reason.
this code works fine without the for loop, but that is where this problem seems to start. in case this also was not clear , I want to run the code on many files so i want the file names in a for loop.

thank you
From: Matt Fig on
"Sean Douglas" <seanjdouglas(a)hotmail.com> wrote in message
> where i ask matlab to open variable yy, which i think the yy variable should indicate file 'ATW' , it seems maybe matlab is only reading the first letter 'A' for some reason.
> this code works fine without the for loop, but that is where this problem seems to start. in case this also was not clear , I want to run the code on many files so i want the file names in a for loop.
>
> thank you

This is why I wrote what I did in my first response. Look at this:

for xx= {'TSO' 'VLO'} ,xx,end