How does READTABLE deal with strings?
Show older comments
With the following files I notice different behaviour of "readtable" in different MATLAB releases:
% File 1: readtable_test1.txt
id another_string age
100 10
101 grr" 1
102 "grr2" 2
% File 2: readtable_test2.txt
id another_string age
100 10
101 grr" 1
102 "grr2" 2
103 "grr3 3
% File 3: readtable_test3.txt
id another_string age
100 10
101 grr" 1
102 "grr2" 2
103 "grr3 3
104 grr"4 4
When running:
readtable('readtable_test1.txt','Delimiter','\t')
R2014a and R2014b both produce the same output.
With:
readtable('readtable_test2.txt','Delimiter','\t')
R2014a reads the table without issues, considering the double quotes (") to be part of the field. 2014b most likely considers a " to be a delimiter, and produces an error due to failure to close the quote.
And for:
readtable('readtable_test3.txt','Delimiter','\t')
R2014a and R2014b both run successfully, but produce difference output. R2014a considers all double quotes to be part of the string fields defined by tab delimiters, and reads the table without trouble. R2014b incorporates multiple table rows, despite tab delimiters, into a single table entry.
This behavior appears to be inconsistent and I would like to understand why.
Accepted Answer
More Answers (0)
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!