how to convert a timetable to structure of timetables
8 views (last 30 days)
Show older comments
hi, I'm looking for some pointers/advice on how best to move data from a timetable to a structure contataining individual variable timetables.
TT = Time, var1 , var2, var3, etc
to
struct containing Time,var1 ; Time var2; Time var3; etc...
thanks in advance
0 Comments
Accepted Answer
Guillaume
on 2 Feb 2020
Edited: Guillaume
on 2 Feb 2020
table2struct(timetable2table(yourtimetable))
%or possibly
table2struct(timetable2table(yourtimetable), 'ToScalar', true)
However, tables and timetables are a lot easier to work with than structures, so it's a bit odd to want to do that. Can you explain the reason behind it?
4 Comments
Guillaume
on 3 Feb 2020
fn is indeed the input variable of the anonymous function that will receive in turn each element of the cell array fields. All cellfun is doing is iterating over each variable of the timetable to return only that portion of the timetable. This is all concatenated as the 2nd row of a cell array, with the first row the actual variable names.
Expansion of cell arrays into a comma separated list allows us to pass that as inputs to the struct function.
More Answers (0)
See Also
Categories
Find more on Data Type Identification 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!