Also why does MATLAB name the time "Time" and not "time"? The time is an array not a struct, and should be lowercase, shouldnt it?
How do you name time series / table variables?
47 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Steven Lord
on 6 Feb 2021
My advice is to name the variable that contains your timetable array something that makes sense for your application. If you're using a timetable to store the temperature measured at (for example) Boston's Logan Airport then an appropriate name might be airportTemp or Logan or even just temperatures (especially if the timetable has entries for other locations along with a variable stating where the measurements were taken.) Similarly the names of the variables in your timetable should make sense for your application. If I had that timetable of Logan Airport temperature measurements any of F (for Fahrenheit), Temp, or measurement might be appropriate names for that variable.
Don't read too much into the default name for the time dimension being Time instead of time. The name refers to time because this is a timetable not a table. And if you specify a different variable name as the times of your timetable the first dimension name may be different. Using the example from the timetable help text:
MeasurementTime = datetime({'2015-12-18 08:03:05';'2015-12-18 10:03:17';'2015-12-18 12:03:13'});
Temp = [37.3;39.1;42.3];
Pressure = [30.1;30.03;29.9];
WindSpeed = [13.4;6.5;7.3];
WindDirection = categorical({'NW';'N';'NW'});
TT = timetable(MeasurementTime,Temp,Pressure,WindSpeed,WindDirection)
TT.Properties
The first dimension is MeasurementTime not Time. The error message you receive if you ask TT for its time data makes this clear.
TT.MeasurementTime
TT.Time % will not work
6 Comments
Steven Lord
on 6 Feb 2021
Let's make some arbitrary data.
v = 0:0.5:10;
rawdata = {(1:5).', 40 + randi([-10 10], 5, 1), ...
reshape(v(randperm(numel(v), 8)), 8, 1), 1 + randn(8, 1)};
temperature = timetable(minutes(rawdata{1}), rawdata{2})
pressure = timetable(minutes(rawdata{3}), rawdata{4})
The names of the two arrays seem reasonable, temperature and pressure. I assume you're asking what you should name the variables with the default name of Var1 in each of these arrays? What makes sense for your application. If those temperature measurements were for the temperature outside (during a New England winter day, the temperature can fluctuate wildly but not usually that wildly!) maybe:
temperature.Properties.VariableNames{1} = 'outside temp'
You might also want to give it a unit for use when the timetable is summarized.
temperature.Properties.VariableUnits{1} = 'degrees F'
summary(temperature)
It sounds a little like you're looking for Absolute Rules of Variable Naming in MATLAB, inscribed on tablets brought down from On High (one of the offices on the top floor of our Apple Hill headquarters.) Those don't exist.
Well, okay there are some rules you can't violate for standalone variable names (see the isvarname function for that list.) However some of those rules don't apply (anymore) to variable names inside a table ('outside temp' is not a valid standalone variable name as it contains a space but is allowed as of a recent release as a table variable name.)
As guidelines I would say:
- Make your variable names meaningful. Ideally you shouldn't have to explain what your data represents to someone who has read the variable names. The more your code / data explains, the less time you have to take explaining it to others and the more time you can spend working with your code / data.
- Make your variable names as long as they need to be, no longer and no shorter.
- Be consistent within your code. Don't use temp one place, Temp another, and tEmP a third. [Personally I'd advise you not to use that third one at all.]
- If appropriate be consistent with others' code as well, especially if you need your code / data to interface with theirs.
dpb
on 6 Feb 2021
"... let's say I don't want combine them. How should I name the timetables and its variables?"
Again, w/o more details of what you're going to be doing with them, if it really is reasonable to not combine tables, I'd suggest an array of tables would be a practical solution to solve both naming problems of what the table(s) are named as well as the internal variable(s).
Personally, given my preference for coding style, I'd almost certainly combine the tables unless the times are inconsistent and there never will be a wish to synchronize them but treat them all as totally independent.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!