Azzera filtri
Azzera filtri

finding/changing name of timetable 'Time'column

96 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Adam Danz
Adam Danz il 14 Mag 2019
Modificato: Adam Danz il 14 Mag 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 Commenti
Andrew J
Andrew J il 14 Mag 2019
I hadnt found RowTimes - idea1 is perfect ...
Adam Danz
Adam Danz il 14 Mag 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by