Convert a Cell array to a timetable

조회 수: 3 (최근 30일)
CSCh
CSCh 2024년 11월 26일
이동: Steven Lord 2024년 11월 29일
Hi, I have
A1=1x78995 cell array;
cell array {1x1800 double} {1x1800 double}.....
And A2 1x78995 cell with datetimes.
How can a create a timetable like
Time=timetable( [A2{1:78995}]',[78995x the first value of1800]'......,[78995x the last value of 1800])
so that I have a timetabel of 78995x1801 at the end.
Thank you.
  댓글 수: 1
Jacob Mathew
Jacob Mathew 2024년 11월 26일
Hey CSCh,
Could you share the data or a snippet of it ?

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

채택된 답변

Steven Lord
Steven Lord 2024년 11월 26일
If you have a set of row vectors in a cell array
sampleCell = {1:10, 11:20, 21:30};
first to accomplish your stated goal you need to transpose them into column vectors.
sampleCellTransposed = cellfun(@transpose, sampleCell, UniformOutput=false);
Then pass them into the table or timetable function as a comma-separated list.
T = table(sampleCellTransposed{:})
T = 10x3 table
Var1 Var2 Var3 ____ ____ ____ 1 11 21 2 12 22 3 13 23 4 14 24 5 15 25 6 16 26 7 17 27 8 18 28 9 19 29 10 20 30
To make a timetable, of course one of the inputs must contain time-based data. In this case since none of the cells in sampleCellTransposed do, I pass it in as the first input argument.
dt = datetime('today')+(0:9).';
TT = timetable(dt, sampleCellTransposed{:})
TT = 10x3 timetable
dt Var1 Var2 Var3 ___________ ____ ____ ____ 26-Nov-2024 1 11 21 27-Nov-2024 2 12 22 28-Nov-2024 3 13 23 29-Nov-2024 4 14 24 30-Nov-2024 5 15 25 01-Dec-2024 6 16 26 02-Dec-2024 7 17 27 03-Dec-2024 8 18 28 04-Dec-2024 9 19 29 05-Dec-2024 10 20 30
  댓글 수: 1
CSCh
CSCh 2024년 11월 28일
이동: Steven Lord 2024년 11월 29일
Thank you Steven,that helps me a lot.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by