From: Sean Douglas on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <i2n3nq$8st$1(a)fred.mathworks.com>...
> "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

Hey Matt,

ok, I changed the brackets
i maybe dont know what you mean by : ",xx,end" but i think you are just indicating i need to have xx show up later and then end the for loop. Since this is not helping, I have tried different variations of what you wrote.

this is what i now have:
clear;
format long g
start1=20070101
upto1=20100601

for xx={'APC' 'BHI'};
for yy={'ATW' 'USO'};

[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);

....still getting errors:
??? Error using ==> xlsread at 122
Filename must be a string.

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

im still trying to read about putting strings for files into for loops, but im not finding the most relevant articles on this.
thanks Matt
From: us on
On Jul 27, 7:33 pm, "Sean Douglas" <seanjdoug...(a)hotmail.com> wrote:
> "Matt Fig" <spama...(a)yahoo.com> wrote in message <i2n3nq$8s...(a)fred.mathworks.com>...
> > "Sean Douglas" <seanjdoug...(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
>
> Hey Matt,
>
> ok, I changed the brackets

>   for yy={'ATW' 'USO'};
> [num, txt]=xlsread(yy);

> ...still getting errors:
> ??? Error using ==> xlsread at 122
> Filename must be a string.

learn to LOOK at things(!)...

- what is yy...
- then: THINK
- then: THINK, again
- what would yy{1} be...
- then: POST (maybe)

us
From: Matt Fig on
"Sean Douglas" <seanjdouglas(a)hotmail.com> wrote in message
> ok, I changed the brackets
> i maybe dont know what you mean by : ",xx,end" but i think you are just indicating i need to have xx show up later and then end the for loop. Since this is not helping, I have tried different variations of what you wrote.


I meant for you to copy that line into the command window and look at what you get versus what you originally had. You are supposed to realize that you need to use a cell array.

Try these (copy and paste):

% Alternative 1
D = {'ABC', 'DEF'}; for xx=1:2 ,D{xx},end

% Alternative 2
for xx= {'ABC', 'DEF'} ,xx{1},end

Now you should get strings, not cells, in the loop.
From: Andy on
Try this:

for yy = {'ATW' 'USO'}
yy
class(yy) % important!
end

The error message is, of course, correct. The variable yy is not a string. You can instead try:

for yy = {'ATW' 'USO'}
[num, txt] = xlsread(yy{1});
end

You should try to do this simpler debugging on your own without resorting to posting to the newsgroup. You'll learn the language much faster if you see what it's doing during basic operations. Type

dbstop if error

at the command line before running your script. Then, if it errors, it will stop executing and allow you to examine the values of the variables in the workspace to see what the problem is.
From: Jan Simon on
Dear Matt Fig,

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

Is this a documented feature? It worked in Matlab 6.5 already, but I cannot find a hint in the help or doc.

Deeply impressed to learn something new about such a basic function, Jan