read empty line by textscan
Mostrar comentarios más antiguos
Hi Everyone,
I am trying to organize a txt file with 12000 lines, which is too large to use readtable. And i choose to use textscan.
But the problem is textscan just skip all the empty lines, but i need to the exact lines number of certain element in the original file.
I searched a lot online but didn't help. i tried code like this to delete all whitespace but doesn't help.
default = textscan(fid,'%s%s','Delimiter','=','whitespace', '')
Thank you for your help!
2 comentarios
Rik
el 11 de Abr. de 2019
Did you try either suggested solution? If you still have issues, we'll be happy to help.
Jeremy Hughes
el 11 de Abr. de 2019
I know someone has already added a solution, and it's a fine solution for what you're doing. But I'm surprised that READTABLE has a problem. Can you attach a sample?
12,000 lines isn't all that large especially if there are only two columns.
If you have 19a, you might also try:
M = readmatrix(filename,'OutputType','string','Delimiter','=','Whitespace','')
Respuesta aceptada
Más respuestas (1)
Bob Thompson
el 10 de Abr. de 2019
Editada: Rik
el 10 de Abr. de 2019
I'm going to guess that the extra lines are not consistent?
Generally, I would suggest reading the entire file in as one string, then splitting it at the new line characters. The exact coding may be a bit off from the below example, but it should put you on the right track.
default = textscan(fid,'%s'); % Read the file as one block
default = regexp(default,'\n','split'); % Split the string into multiple cells at each new line character
3 comentarios
Rik
el 10 de Abr. de 2019
I suspect you mean regexp instead of repmat.
Bob Thompson
el 10 de Abr. de 2019
Yes, I do. Thank you for catching that, I was using repmat for other things recently.
zhiwen wan
el 11 de Abr. de 2019
Categorías
Más información sobre Characters and Strings 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!