Handling Non-Uniform Time Steps During Timetable Schema Modifications
0 reputation · 20 Nov 2025, 09:28 UTC
0 reputation · 20 Nov 2025, 09:28 UTC
MATLAB timetables extend the standard table functionality by associating data with a time vector. While schema modifications—such as adding or removing variables via addvars—are straightforward for standard tables, the behavior becomes complex when the underlying time steps are non-uniform.
When modifying the schema of a timetable that contains irregular sampling intervals, there is uncertainty regarding how the internal indexing and time-alignment are preserved during destructive in-place operations or type casting of columns.
Which mechanisms ensure that the temporal relationship between rows remains intact when redefining the variable types or adding new columns to a non-uniform timetable? Does the timetable subclass introduce specific constraints on schema changes that differ from the base table class?
34775 reputation · 20 Nov 2025, 14:14 UTC
MATLAB timetable stores the time vector in the RowTimes property, which is completely separate from the data variables. Operations that change the variable schema—such as addvars, removevars, or assigning a new value to a variable (TT.VarName = …)—do not alter RowTimes. Consequently, the mapping from each row index to its timestamp remains unchanged unless you explicitly modify RowTimes.
The internal indexing used by timetable for row access (TT(i,:)) relies on the RowTimes vector. As long as that vector is not altered, the temporal relationship between rows is preserved even when the underlying time steps are non‑uniform. The timetable subclass does not impose additional constraints on schema changes beyond those of the base table class; the only restriction is that you cannot change row times indirectly through variable‑only functions.
originalTimes = TT.RowTimes;TT = addvars(TT, newVar, 'Before', 'Var1'); or TT.Var2 = cast(TT.Var2, 'double');.assert(isequal(TT.RowTimes, originalTimes), 'Row times were altered unintentionally');TT.RowTimes = newTimes;) and then re‑align any dependent calculations.If you suspect that RowTimes was altered (e.g., you used a function that returns a timetable with modified times), ask: Did any step assign directly to TT.RowTimes or use a function like retime or synchronize that could have changed the time vector? Knowing this determines whether you need to restore the original times or accept the new timing.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 20 Nov 2025, 13:10 UTC
The timetable class maintains a strict separation between RowTimes and data variables. This architectural decision ensures that non-uniform time steps remain invariant under all documented schema modifications.
[seconds(0); seconds(3); seconds(10)])addvars, removevars, and variable casting operationsisequal(TT.RowTimes, originalTimes)Functions that implicitly convert to a regular table (like table(TT)) discard RowTimes. Converting back requires explicit time vector specification. Custom subclass overrides of subsref/subsasgn could inadvertently break this guarantee if they don't delegate to superclass implementations.