Problem with XLS files read and write
Mostrar comentarios más antiguos
Dear All, I have a single file with a table of 8 column and 200 raw. I would like to create a function that open the XLS file and create 200 XLS files each one with the 8 value of each raw. Can somebody help me please? thanks a lot
Respuestas (1)
the cyclist
el 7 de Dic. de 2011
0 votos
Have you tried the xlswrite() and xlsread() functions?
EDIT in response to comment:
You provided no detail on what you have tried, or where you are stuck. Here is the general approach I would take:
-- Use xlsread() to read the origin file into a variable
-- Use a for loop that
- extracts each row of that variable
- creates a unique filename for each row
- writes that row to file using xlswrite()
Maybe you could take that approach, and see if you get stuck anywhere. If you do, then post your code and your specific question about where you are stuck.
12 comentarios
Maurizio
el 7 de Dic. de 2011
Maurizio
el 7 de Dic. de 2011
the cyclist
el 7 de Dic. de 2011
Are you using this syntax for xlsread: [num,txt,raw]=xlsread(...)?
Then "num","txt", and/or "raw" should be usable in much the same way as you had been using OrgFileTxt, depending on the contents of your file.
I have to admit that I am relying on old memories of xlsread(), because I have not used it in several years. (That command does not work very well on Macs.)
Maurizio
el 7 de Dic. de 2011
the cyclist
el 7 de Dic. de 2011
"raw" is a cell array with your data, right? What size is it?
I think you need two steps: (1) Make each individual row variable from the cell array "raw". (2) Write that row to the file.
Which of those two steps are you stuck on? Or maybe it is something else?
Maurizio
el 7 de Dic. de 2011
Maurizio
el 7 de Dic. de 2011
the cyclist
el 7 de Dic. de 2011
Are you getting a MATLAB error message from that code? If so, what is the message? If not, what do you mean by "error"? Do you get output files, but they don't look as you expect?
Maurizio
el 7 de Dic. de 2011
the cyclist
el 7 de Dic. de 2011
You could try [all{1,:}] to concatenate all the elements of the first row into one long array. However, if the variables are of mixed type, that won't work. You may have to do more processing on each piece of data, to see the best way to put them all together.
Maurizio
el 7 de Dic. de 2011
the cyclist
el 7 de Dic. de 2011
all(1,:) is the first row of the cell array, so it will be a 1xN cell array. You could try to do xlswrite{'fn',num2str(k),'.xls',all(1,:),'a1:u1'};
I'm not sure if xlswrite() works like that, and I cannot test it here.
If it is acceptable for you to have CSV files instead of XLS files as output, you could use the File Exchange function cellwrite(), available here: http://www.mathworks.com/matlabcentral/fileexchange/7363-cellwrite
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!