Can I loop xlsread to open files?

조회 수: 1 (최근 30일)
Laurentiu Galan
Laurentiu Galan 2011년 11월 14일
Basically I want to open a bunch of Yahoo Finance FIles and parse them because they come in a really ugly format (can't use csvread).
How would I fix this code to be able to open the existing files in a directory. I have written the following:
Now once i've opened each one, how do i grab the values for A and newmat and put them together in a matrix and output a .csv file with them together in in 'c:\Users\Laurentiu Galan\Desktop\tickoutput3\*.csv'?
Thanks. I have no idea how to use the directory so if i could do it with xlsread that would be great. Other users have suggested that in the past, but I cant get that to work.
%Matlab code to create matrix for files
Files = dir('c:\Users\Laurentiu Galan\Desktop\tickoutput2\*.csv');
fnames = {Files.name};
filename = fnames';
%Determine Size for Loop
D = size(filename);
Numloop = D(1,1);
%Loop to Create Paths for each file
for i=1:Numloop
thispath(i,1) = strcat('c:\Users\Laurentiu Galan\Desktop\tickoutput\', filename(i,1));
end;
%Loop to Loop
for i=Numloop
[numericalData, textData] = xlsread('thispath(i)');
newmat=flipud(numericalData(2:end, 6));
A = flipud(textData(2:end, 1));
end

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 11월 14일
I don't understand your difficulty. The answer to your previous question has shown you how to find all the .csv file in a particular folder and loop through them.
It has nothing to do with a directory. Any time when you read or write a file. You could either use just the file name, or you can use the full path plus the file name. The latter approach is always more robust.
Your .csv file may contain both numerical and string data. Using xlsread() is a good idea. But if you have more than 2300 .csv files, using xlsread() is going to take lots of time. You could use Excel COM server to speed it up. See the following post. It has been reported 7 times faster with just about 300 files.
Don't stuck with your code. If you ask a question and got an answer, try to read, follow the advice and at least try it. The answer is not meant to give your the complete solution. It is meant to open the door and guide you to find the solution. I believe the answer to your previous question is sufficient if you try it and understand it.
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2011년 11월 14일
Excel COM server comes with MATLAB if you have MS Excel installed on a PC.
Laurentiu Galan
Laurentiu Galan 2011년 11월 14일
thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 11월 14일
xlsread(thispath{i})
and go back to the directory structure Fangjun showed in your previous posting on this topic.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by