how to let 'textscan' stop when read an empty line
Mostrar comentarios más antiguos
I have double quoted csv file:
"header1"
(descriptions)
"A","B","3","A","B","3"
"C","B","3","T","B","2"
"D","B","3","A","H","3"
"E","B","3","A","B","6"
"F","B","3","Z","J","3"
(empty line here)
"header2"
(descriptions)
"A","B","3","A","B","3"
"C","B","5","A","B","3"
"D","B","4","A","H","3"
"E","B","3","A","L","1"
"F","B","2","A","I","3"
I tried to use:
fid=fopen('..\data.csv', 'r')
fgetl(fid)
fgetl(fid)
inputtext = textscan(fid, '%q%q%q%q%q%q', ...
'delimiter', ',');
but it reads everything until hits the end of the data file (including header2). How to read data above the empty line? Thanks!!
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 24 de Jul. de 2012
0 votos
textscan() is not designed for this.
You can remove newline from the Whitespace list, but to compensate you have to explicitly match newline in your textscan() format at the point you expect newline to be.
2 comentarios
Walter Roberson
el 24 de Jul. de 2012
That particular demo is reading blocks of floating point numbers rather than strings. Different stopping conditions internally, unfortunately.
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!