Borrar filtros
Borrar filtros

Can I loop xlsread to open files?

1 visualización (últimos 30 días)
Laurentiu Galan
Laurentiu Galan el 14 de Nov. de 2011
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

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 14 de Nov. de 2011
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 comentarios
Fangjun Jiang
Fangjun Jiang el 14 de Nov. de 2011
Excel COM server comes with MATLAB if you have MS Excel installed on a PC.
Laurentiu Galan
Laurentiu Galan el 14 de Nov. de 2011
thanks

Iniciar sesión para comentar.

Más respuestas (1)

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

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by