Nested table to writetable()
11 views (last 30 days)
Show older comments
This is a similar question to [1]. In a for-loop, I opened a lot of files, processed them and saved into struct. In the end, I want to convert all structures to a table and export to a CSV file.
Unfortunately, I get something like "date1, date2, date3" since writetable() until now does not seem to support nested tables (as can be seen in the question above). My table looks like this:
date Lat Lon
________________ ______________ ______________
{133×1 datetime} {133×1 double} {133×1 double}
{133×1 datetime} {133×1 double} {133×1 double}
{133×1 datetime} {133×1 double} {133×1 double}
{133×1 datetime} {133×1 double} {133×1 double}
{133×1 datetime} {133×1 double} {133×1 double}
{133×1 datetime} {133×1 double} {133×1 double}
{133×1 datetime} {133×1 double} {133×1 double}
{133×1 datetime} {133×1 double} {133×1 double}
Is there maybe any possibility to flatten or unnest the table?
1 Comment
Eric Sofen
on 2 Oct 2020
Edited: Eric Sofen
on 2 Oct 2020
Do you want the timetable to look like that or do you want the data out of the cell arrays and vertically concatenated? That is, do you want a table (or maybe timetable) that's 1064 rows tall instead of 8? If so, you'll probably want to undo whatever you're doing that's wrapping the columns in cells. If that's not an option, the data in the state it's shown above can't really expand them all in one step, although it can be done by iterating over the variables using varfun:
>> t
t =
2×2 table
Var1 Var2
____________ ____________
{3×1 double} {3×1 double}
{2×1 double} {2×1 double}
>> varfun(@(x) vertcat(x{:}),t)
ans =
5×2 table
Fun_Var1 Fun_Var2
________ ________
1 6
2 7
3 8
4 9
5 10
Answers (0)
See Also
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!