Problem of writing a mixed type cell array to a csv file
Mostrar comentarios más antiguos
Hi! I have an issue regarding read/write on csv file. I have a large csv file containing mixed type of data(double and string). when I open the file using a text editor it is in the proper format and comma separated data. Also when I open it using excel(Excel 2013) it is displayed properly. Next,in my code, I read the data using xlsread() and choose some rows and assign them to a cell array. so the format looks similar to the initial file and I write the cell array to another csv file using xlswrite(). Now, when I open the file in excel it alerts that "the file may be corrupted. do you still want to open it?" but it is loaded and displayed properly. but when I open it using wordpad all it is shown is garbage values. Where is the problem? is there any write eqivalent to textscan so that I could write the file in a comma separated format?
Thanks
Respuesta aceptada
Más respuestas (1)
Iain
el 10 de Sept. de 2014
0 votos
If you want to write it as a csv file and if it must be a csv file and the data is really variable format, then you may have to literally go through the entire cell array turning all the numerical values into strings, and then write them to disk using fprintf.
If you want to do it in a slightly easier way, why not just use an excel file - and if you then need a csv file, you can always use excel to save it as a csv.
It depends how often you want to do it, but you can also use "actxserver" to make excel generate your csv with the formatting you want. This might be a better solution to manually doing it all.
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!