Nested table to writetable()

조회 수: 7 (최근 30일)
Frederik
Frederik 2020년 7월 14일
편집: Eric Sofen 2020년 10월 2일
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
Eric Sofen
Eric Sofen 2020년 10월 2일
편집: Eric Sofen 2020년 10월 2일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by