Clear Filters
Clear Filters

finding/changing name of timetable 'Time'column

96 views (last 30 days)
For a given timetable - how can you find out the name of the Time column - and (if desired) change it ?
The 'Time' column is a type of row/record key - not a normal var column - so (as far as I know) it's name cant be accessed using t.Properties.VariableNames or similar.
By default it has the name 'Time' - so can be accessed by t.Time etc - but this does not have to be - for example if the timetable is imported from elsewhere, where it was created from a table in which the 'Time' column was actually called 'Date' - then the 'time column' exists in the timetable - but trying to access it isnt easy - because its name is not 'Time' - and I havent yet found a simple way to programatically determine what it is called - in the general case - or to change it, if required.
The only way that I have found to do these things is to convert the timetable to a table - access its metadata - change things if required - and then convert back to a timetable - which seems very cumbersome.
A

Accepted Answer

Adam Danz
Adam Danz on 14 May 2019
Edited: Adam Danz on 14 May 2019
Idea 1: No need to change the name
If you're trying to access the time stamps, you don't need to know the name of the time column. You can get the time stamps like this:
% TT is the timetable
TT.Properties.RowTimes %no matter what the time column is named!
Idea 2: Access DimensionNames
The DimensionNames property stores the name of the time column in the first of two elements of a cell array.
% This tells you the time column name
TT.Properties.DimensionNames{1}
% Change the name like this
TT.Properties.DimensionNames{1} = 'TimeName';
  2 Comments
Andrew J
Andrew J on 14 May 2019
I hadnt found RowTimes - idea1 is perfect ...
Adam Danz
Adam Danz on 14 May 2019
Glad it worked for you.
Working with tables is nice because the data are tidy and they stay organized. When you use Idea #1, you're leaving the table workflow which relinquishes the benefits of working with a table. Just something to keep in mind.

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!