textscan scuppered by '\n' mid entry

I have a csv file that annoyingly has some string entries that have newlines within the entry. Therefore when textscan comes across this entry it thinks it has reached the end of the row and tries to start a new one, where it halts scanning.
I tried to skip this field using %*s which doesn't work. Is there a way to ignore the '\n' signifier in between delimiters?

Réponses (1)

Image Analyst
Image Analyst le 25 Juin 2014
You can pre-process the file. Pseudocode:
open file
while not EOF
read a line with fgetl
count commas
if commas not the expected amount
read next line
stitch both lines together
count commas again.
if commas not the expected amount, it's an error
Alert user via warndlg
end
end
write line to output file
end

2 commentaires

harry
harry le 25 Juin 2014
Ok cool, that sounds good. So say instead of new lines (\n) commas were mid entry (as this damned file has), one wouldn't be able to stitch the next line as with the new line case, we would actually have to remove it. If this comma doesn't occur in a consistent position, how do you think we solve this?
Thanks!
Image Analyst
Image Analyst le 25 Juin 2014
I didn't understand. Are you saying that you have two commas in a row or missing or extra commas? Please give an example of that type of line.

Cette question est clôturée.

Produits

Question posée :

le 25 Juin 2014

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by