How do you name time series / table variables?
Afficher commentaires plus anciens
Hello community,
when having a dataset with much variables in the form of a timetable, I often name the table with its variables something like:
Data.Time
Data.temperature
Data.current
etc...
However it happens quite often, that I have a time series in the form of a timetable, which only is made from one measurement.
This makes me always wondering how I should call those variables, since I dont want the timetable be called "Data".
At the moment I am using mostly something like:
Temperature.Time
Temperature.Values % Temperature.Value? Temperature.Data? Temperature.temperature??? I hate it.
How would you name souch a timetable?
There is no "right" answer here, so my favorite one after a day or so will be accepted :)
14 commentaires
Maximilian Schönau
le 5 Fév 2021
dpb
le 5 Fév 2021
I generally use a preceding lowercase 't' for a table variable and 'tt' for a timetable to remind the storage type.
I have no set rule for capitalization of variables other than try to be consistent within a given table just for sanity and appearance--with automagic name completion via the tab key, it's not that big of a deal.
I am certainly not in favor of VeryLongandVerboseandMindlessFollowingCamelCaseVariableNames, however; I am far more likely to use just tTemp or the like for the table you outline above, very likely the temperature variable inside the table will be just "T". I hate excess typing on input and imo longer names just obscure the code intent by making harder to parse the actual statement content.
Maximilian Schönau
le 5 Fév 2021
Mario Malic
le 5 Fév 2021
Modifié(e) : Mario Malic
le 6 Fév 2021
I use lowercase camel for variables, structures, most of the stuff basically and uppercase camel for functions, properties. I switched from uppercase snake case, as that code now looks to me "harsh" to read. It all depends on the context you are programming in, especially in OOP, where it's quite good to know whether the variable is class or property or variable.
Where do you see this? Also why does MATLAB name the time "Time" and not "time"?
"Time" is the default name TMW chose for the time column in a timetable if the user doesn't specify a different name or use a variable of another name -- in that case it will use the user-defined name.
It's Time instead of time simply in order to be case-consistent with the capitalization convention of the default variable names being Var1, Var2, ... It would look peculiar otherwise.
"a one letter name, which just seems weird in my programming style (never having one letter variables)..."
You're simply too young to remember "the good old days" of keypunches and Dartmouth BASIC with at most two-letter variable names (a letter with an optional single digit).
We of that era are perhaps permanently scarred...
"...and uppercase for functions, properties"
Really? User functions are all UPPERCASE()??? How F77-like! ::)
About the only place I use all uppercase is for constant data arrays like for lookup tables, etc., to identify them as being invariant data (oh for an invariant data type in MATLAB a la PARAMETER or such).
dpb
le 6 Fév 2021
"A problem about names like temperature.T would also acure when combining it with a different table on the way (which in my case often happens). Than you would be forced to rename the variable..."
What's the difference? If you use abracadabra for a magic variable name in some table, if it occurs in another which you're going to catenate horizontally it'll have to change, too.
Whether it is just T or whether it is temperature or Temp or whatever, unless you create totally unique names everywhere you'll run into the same issue. Hence, why not use the conventional, concise that a temperature is T; to catenate, instead of creating more variables, use arrays. There are a million threads on Answers of the problems people generate for themselves by creating series of variables as sequentially-numbered independent variables instead.
if it is the exterior temperature and another is an interior, then name them as Tint, Text or somesuch, but use the same idea of arrays of those for multiple cases or whatever, not new, independent variable names for what are, fundamentally, the same thing. This is especially true when same operations are going to be performed on the different instantiations; independent names breaks vectorized code; the whole advantage of MAT(rix)LAB(oratory).
Maximilian Schönau
le 6 Fév 2021
Mario Malic
le 6 Fév 2021
Uppercase camel, I thought it wouldn't be necessary to add the camel because it was in the same sentence. Actually I switched to camel case because I have seen code of one of the veterans here, and thought, oh, this looks nice!
Maximilian Schönau
le 6 Fév 2021
Modifié(e) : Maximilian Schönau
le 6 Fév 2021
", why should any array be uppercase?"
Why should it NOT be uppercase? Var1 thru VarN are capitalized, surely wouldn't make sense to have only the time variable be all lowercase and the variables capitalized or vice versa. And, as Steven L notes, there's no deep hidden meaning in a variable name, anyway; it's just a name.
If you prefer some convention, you're at liberty to choose the name you want; you can update the variable names at will in the table.Properties.VariableNames cell array. As it clearly illustrates, they're just name strings associated by column position; they have no bearing other than as that reference.
And, the rowtimes name is no different; see the example:
tt=timetable; % an empty table object
tt=[tt;array2timetable(rand,'RowTimes',datetime(date))]; % add a variable
>> tt % see what we gots...
tt =
timetable
Time Var1
___________ _______
06-Feb-2021 0.49865
>>
rowtimes and variable names are capitalized by default.
tt.Properties.VariableNames=lower(tt.Properties.VariableNames);
tt.Properties.DimensionNames(1)=lower(tt.Properties.DimensionNames(1));
>> tt
tt =
timetable
time var1
___________ _______
06-Feb-2021 0.49865
>>
Now they're both uncapitalized; could have changed either to anything in the world wanted to be...the row times column doesn't even have to be named anything related to time:
>> tt.Properties.DimensionNames(1)={'Fred Flintstone'}
tt =
timetable
Fred Flintstone var1
_______________ _______
06-Feb-2021 0.49865
>>
>> tt.('Fred Flintstone')
ans =
datetime
06-Feb-2021
>>
Maximilian Schönau
le 6 Fév 2021
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!