How to write/read a table to/from a CSV that has multiple values per column?
Show older comments
If I create a table with multiple values per column like so:
x = [1,2,3];
y = 4;
T = table(x,y)
outputs
T =
1x2 table
x y
___________ _
1 2 3 4
such that T.x stores three values, 1 2 and 3. If I use writetable and readtable to save/load this table into a CSV file, like so:
writetable(T,"table.csv");
T2 = readtable("table.csv")
outputs
T2 =
1x4 table
x_1 x_2 x_3 y
___ ___ ___ _
1 2 3 4
How can I read in this table such that x_1, x_2, and x_3 are grouped under one header, like in T?
Accepted Answer
More Answers (1)
Hi,
after importing the data in the format you dont want, you could use the mergevars function to change the table like you expect it:
T=mergevars(T,[1 2 3], 'NewVariableName','x')
Best regards
Stephan
1 Comment
Jay Franklin
on 27 Jun 2018
Edited: Jay Franklin
on 27 Jun 2018
Categories
Find more on Tables 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!