Clear Filters
Clear Filters

How do you name time series / table variables?

34 views (last 30 days)
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:
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.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 :)
Maximilian Schönau
Maximilian Schönau on 6 Feb 2021
I just want consistensy within my code, and as far as I know, uppercase arrays are classes or structs for the most programmers.
Like I said, I dont want to change the default name for Time. Altough it is possible to do that, it is annoying. I even remember that in my use case I needed at some point extra lines of codes just to change Time to t which I started to use in the beginning of my project and got annoying quite fast. Sadly I cannot access those lines of codes, maybe I the extra line was not necessary.
However, the default is the simplest solution, that is the reason I want to use Time as my time. I just dont know why it is uppercase and if I should make all of my variables uppercase, to be consistent. Surely, some MATLAB engineer was following some guideline when naming time Time? I noticed, that variables in a struct like a figure are also uppercase, so does someone know a specific convention?
I found myself in a similar problem when using the appdesigner. MATLAB is build in a way, that it is in a few cases the best solution to use the default names given by the programm.
And since I want my code be consistent, regardless if I named the variable or MATLAB did, I want to know what the MATLAB guidelines are.
dpb on 6 Feb 2021
Edited: dpb on 7 Feb 2021
"I want to know what the MATLAB guidelines are."
There aren't any...the best you can do is see what the default naming convention is in any given place -- for a table or timetable, it's a capitalized name string.

Sign in to comment.

Accepted Answer

Steven Lord
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 = 3x4 timetable
MeasurementTime Temp Pressure WindSpeed WindDirection ____________________ ____ ________ _________ _____________ 18-Dec-2015 08:03:05 37.3 30.1 13.4 NW 18-Dec-2015 10:03:17 39.1 30.03 6.5 N 18-Dec-2015 12:03:13 42.3 29.9 7.3 NW
ans =
TimetableProperties with properties: Description: '' UserData: [] DimensionNames: {'MeasurementTime' 'Variables'} VariableNames: {'Temp' 'Pressure' 'WindSpeed' 'WindDirection'} VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowTimes: [3×1 datetime] StartTime: 18-Dec-2015 08:03:05 SampleRate: NaN TimeStep: NaN CustomProperties: No custom properties are set. Use addprop and rmprop to modify CustomProperties.
The first dimension is MeasurementTime not Time. The error message you receive if you ask TT for its time data makes this clear.
ans = 3×1 datetime array
18-Dec-2015 08:03:05 18-Dec-2015 10:03:17 18-Dec-2015 12:03:13
TT.Time % will not work
Unrecognized timetable variable name 'Time'. If you intended to access the row times, use 'MeasurementTime' for this timetable instead.
Steven Lord
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})
temperature = 5x1 timetable
Time Var1 _____ ____ 1 min 33 2 min 37 3 min 40 4 min 49 5 min 30
pressure = timetable(minutes(rawdata{3}), rawdata{4})
pressure = 8x1 timetable
Time Var1 _______ ________ 8 min 0.94519 1.5 min 2.1517 6 min 1.7082 3.5 min 2.2478 4.5 min 1.4795 3 min 1.1954 0 min -0.25179 9 min 1.2803
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'
temperature = 5x1 timetable
Time outside temp _____ ____________ 1 min 33 2 min 37 3 min 40 4 min 49 5 min 30
You might also want to give it a unit for use when the timetable is summarized.
temperature.Properties.VariableUnits{1} = 'degrees F'
temperature = 5x1 timetable
Time outside temp _____ ____________ 1 min 33 2 min 37 3 min 40 4 min 49 5 min 30
RowTimes: Time: 5x1 duration Values: Min 1 min Median 3 min Max 5 min TimeStep 1 min Variables: outside temp: 5x1 double Properties: Units: degrees F Values: Min 30 Median 37 Max 49
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:
  1. 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.
  2. Make your variable names as long as they need to be, no longer and no shorter.
  3. 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.]
  4. 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.

Sign in to comment.

More Answers (0)


Find more on Tables 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!