finding/changing name of timetable 'Time'column

조회 수: 68 (최근 30일)
Andrew J
Andrew J 2019년 5월 14일
댓글: Adam Danz 2019년 5월 14일
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
Andrew J
Andrew J 2019년 5월 14일
I hadnt found RowTimes - idea1 is perfect ...
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에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by