finding/changing name of timetable 'Time'column
96 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Andrew J
el 14 de Mayo de 2019
Comentada: Adam Danz
el 14 de Mayo de 2019
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
0 comentarios
Respuesta aceptada
Adam Danz
el 14 de Mayo de 2019
Editada: Adam Danz
el 14 de Mayo de 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 comentarios
Adam Danz
el 14 de Mayo de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!