finding/changing name of timetable 'Time'column

96 次查看(过去 30 天)
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

采纳的回答

Adam Danz
Adam Danz 2019-5-14
编辑:Adam Danz 2019-5-14
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 个评论
Adam Danz
Adam Danz 2019-5-14
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by