How do I "readtable" with a CSV file when table elements have newlines or double quotation marks?
103 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jul 2017
Answered: MathWorks Support Team
on 27 Jul 2017
I have a table, "DataTable", in a CSV file with elements that are strings containing line breaks, double quotes, and commas. When I read the table from the CSV file, the table is not the same as the one I had originally.
Why does this happen and how can I read my table using a CSV file?
Accepted Answer
MathWorks Support Team
on 27 Jul 2017
Based on the definition of the CSV format, fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes.
When reading from the CSV, you can explicitly tell "readtable" the format of the file. This option's workflow is documented at the link below:
This is illustrated as follows:
>> opts = detectImportOptions('DataTable.csv');
>> T = readtable('DataTable.csv',opts)
0 Comments
More Answers (0)
See Also
Categories
Find more on Structures 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!