Info

This question is closed. Reopen it to edit or answer.

textscan scuppered by '\n' mid entry

1 view (last 30 days)
harry
harry on 25 Jun 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
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?

Answers (1)

Image Analyst
Image Analyst on 25 Jun 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 Comments
harry
harry on 25 Jun 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 on 25 Jun 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.

Products

Community Treasure Hunt

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

Start Hunting!