
- MATLAB - Home
- MATLAB - Overview
- MATLAB - Features
- MATLAB - Environment Setup
- MATLAB - Editors
- MATLAB - Online
- MATLAB - Workspace
- MATLAB - Syntax
- MATLAB - Variables
- MATLAB - Commands
- MATLAB - Data Types
- MATLAB - Operators
- MATLAB - Dates and Time
- MATLAB - Numbers
- MATLAB - Random Numbers
- MATLAB - Strings and Characters
- MATLAB - Text Formatting
- MATLAB - Timetables
- MATLAB - M-Files
- MATLAB - Colon Notation
- MATLAB - Data Import
- MATLAB - Data Output
- MATLAB - Normalize Data
- MATLAB - Predefined Variables
- MATLAB - Decision Making
- MATLAB - Decisions
- MATLAB - If End Statement
- MATLAB - If Else Statement
- MATLAB - If…Elseif Else Statement
- MATLAB - Nest If Statememt
- MATLAB - Switch Statement
- MATLAB - Nested Switch
- MATLAB - Loops
- MATLAB - Loops
- MATLAB - For Loop
- MATLAB - While Loop
- MATLAB - Nested Loops
- MATLAB - Break Statement
- MATLAB - Continue Statement
- MATLAB - End Statement
- MATLAB - Arrays
- MATLAB - Arrays
- MATLAB - Vectors
- MATLAB - Transpose Operator
- MATLAB - Array Indexing
- MATLAB - Multi-Dimensional Array
- MATLAB - Compatible Arrays
- MATLAB - Categorical Arrays
- MATLAB - Cell Arrays
- MATLAB - Matrix
- MATLAB - Sparse Matrix
- MATLAB - Tables
- MATLAB - Structures
- MATLAB - Array Multiplication
- MATLAB - Array Division
- MATLAB - Array Functions
- MATLAB - Functions
- MATLAB - Functions
- MATLAB - Function Arguments
- MATLAB - Anonymous Functions
- MATLAB - Nested Functions
- MATLAB - Return Statement
- MATLAB - Void Function
- MATLAB - Local Functions
- MATLAB - Global Variables
- MATLAB - Function Handles
- MATLAB - Filter Function
- MATLAB - Factorial
- MATLAB - Private Functions
- MATLAB - Sub-functions
- MATLAB - Recursive Functions
- MATLAB - Function Precedence Order
- MATLAB - Map Function
- MATLAB - Mean Function
- MATLAB - End Function
- MATLAB - Error Handling
- MATLAB - Error Handling
- MATLAB - Try...Catch statement
- MATLAB - Debugging
- MATLAB - Plotting
- MATLAB - Plotting
- MATLAB - Plot Arrays
- MATLAB - Plot Vectors
- MATLAB - Bar Graph
- MATLAB - Histograms
- MATLAB - Graphics
- MATLAB - 2D Line Plot
- MATLAB - 3D Plots
- MATLAB - Formatting a Plot
- MATLAB - Logarithmic Axes Plots
- MATLAB - Plotting Error Bars
- MATLAB - Plot a 3D Contour
- MATLAB - Polar Plots
- MATLAB - Scatter Plots
- MATLAB - Plot Expression or Function
- MATLAB - Draw Rectangle
- MATLAB - Plot Spectrogram
- MATLAB - Plot Mesh Surface
- MATLAB - Plot Sine Wave
- MATLAB - Interpolation
- MATLAB - Interpolation
- MATLAB - Linear Interpolation
- MATLAB - 2D Array Interpolation
- MATLAB - 3D Array Interpolation
- MATLAB - Polynomials
- MATLAB - Polynomials
- MATLAB - Polynomial Addition
- MATLAB - Polynomial Multiplication
- MATLAB - Polynomial Division
- MATLAB - Derivatives of Polynomials
- MATLAB - Transformation
- MATLAB - Transforms
- MATLAB - Laplace Transform
- MATLAB - Laplacian Filter
- MATLAB - Laplacian of Gaussian Filter
- MATLAB - Inverse Fourier transform
- MATLAB - Fourier Transform
- MATLAB - Fast Fourier Transform
- MATLAB - 2-D Inverse Cosine Transform
- MATLAB - Add Legend to Axes
- MATLAB - Object Oriented
- MATLAB - Object Oriented Programming
- MATLAB - Classes and Object
- MATLAB - Functions Overloading
- MATLAB - Operator Overloading
- MATLAB - User-Defined Classes
- MATLAB - Copy Objects
- MATLAB - Algebra
- MATLAB - Linear Algebra
- MATLAB - Gauss Elimination
- MATLAB - Gauss-Jordan Elimination
- MATLAB - Reduced Row Echelon Form
- MATLAB - Eigenvalues and Eigenvectors
- MATLAB - Integration
- MATLAB - Integration
- MATLAB - Double Integral
- MATLAB - Trapezoidal Rule
- MATLAB - Simpson's Rule
- MATLAB - Miscellenous
- MATLAB - Calculus
- MATLAB - Differential
- MATLAB - Inverse of Matrix
- MATLAB - GNU Octave
- MATLAB - Simulink
MATLAB - Timetables
Timetable is data structure available in matlab. It is nothing but tables with rows and columns with each row being timestamped. The data is stored in column-oriented data variables that will have different data types and sizes, but the same number of rows. Timetables provide a variety of time related functions. They deal with align, combine and also allows to do maths on the timestamped data in the given timetables.
Since the data stored are time-stamped , it helps to analyse data and can be useful in different domains and applications.In the real world there is a lot of usage where timetables can be brought into use. Some of the main areas where you can make use of timetables are as follows −
- Medicinal Research − Here you can make use of timetables to store and analyse your data which are related to experiments on drugs and diseases. The experiments can be related to cardio respiratory, stem cells, infection and immunity etc. The data later can be plotted using functions like plot and histogram.
- Stock Market Analysis − The data that comes from the stock market is huge.You can make use of Timetable to store and analyze it. There are other useful methods in matlab that can be used to calculate the numbers.
- Environment Monitoring and Assessment − The data that comes down from environmental studies can be stored in timetables to do further analysis.
- Sensor Data − With Timetables you can analyse and store sensor data related to GPS, temperature etc.
Let us understand in depth the working of timetables in matlab.
Creation of TimeTable
Matlab has many ways to create a timetable , here is a list of it.
- Using timetable() function
- Make use of array2timetable() function
- Make use of table2timetable() function
- Make use of timeseries2timetable() function
Using timetable() Function
Following is the syntax for timetable() function
Syntax
T = timetable(rowTimes,var1,...,varN)
The function timetable() will create a table where var1varN are input data variables. The parameter rowTimes is a time vector. In the above function the data types of the data variables var1..varN can vary but it should have the same number of rows. Same goes to rowTimes which is a vector with datetime or duration.
To create rowTimes will make use of the dateTime() function as shown below −
timer = datetime({'2023-01-01 09:00:00';'2023-01-01 09:30:00';'2023-01-01 10:00:00'});
When you execute the above in Matlab the output is as follows −
>> timer = datetime({'2023-01-01 09:00:00';'2023-01-01 09:30:00';'2023-01-01 10:00:00'}) timer = 31 datetime array 01-Jan-2023 09:00:00 01-Jan-2023 09:30:00 01-Jan-2023 10:00:00 >>
Let us feed the timer and data variables to the timetable function and see the output in Matlab.
T = timetable(timer ,DayTemp ,DayPressure)
On execution in matlab we get the following output
>> timer = datetime({'2023-01-01 09:00:00';'2023-01-01 09:30:00';'2023-01-01 10:00:00'}); DayTemp = [28.3;30.0;33.3]; DayPressure = [23.1;23.03;33.9]; T = timetable(timer ,DayTemp ,DayPressure) T = 32 timetable timer DayTemp DayPressure ____________________ _______ ___________ 01-Jan-2023 09:00:00 28.3 23.1 01-Jan-2023 09:30:00 30 23.03 01-Jan-2023 10:00:00 33.3 33.9 >>
Make use of array2timetable() Function
Following is the syntax for array2timetable() function
Syntax
The function array2timetable() will return a timetable wherein X is an MXN array and rowTimes is a vector array of size Mx1.
Let us see an example to create a timetable using array2timetable() function.
Example
Let us first create a 3x3 matrix as X.
X = rand(3,3)
Now let us create a row vector rowTimes.
rowTimes = seconds(1:3)
Now let us use X and rowTimes in array2timetable() function and see the output
X = rand(3,3) rowTimes = seconds(1:3) TT = array2timetable(X,'RowTimes',rowTimes)
The output when executed in Matlab is as follows −
>> X = rand(3,3) rowTimes = seconds(1:3) TT = array2timetable(X,'RowTimes',rowTimes) X = 0.6787 0.3922 0.7060 0.7577 0.6555 0.0318 0.7431 0.1712 0.2769 rowTimes = 13 duration array 1 sec 2 sec 3 sec TT = 33 timetable Time X1 X2 X3 _____ _______ _______ ________ 1 sec 0.67874 0.39223 0.70605 2 sec 0.75774 0.65548 0.031833 3 sec 0.74313 0.17119 0.27692 >>
Make use of table2timetable() Function
In this we are going to use a table to create a timetable out of it using the function table2timetable().
A table is a data type in Matlab, which stores data in tabular format, just the way you see data in a spreadsheet.
An example of table is as follows −
Name = {'Siya';'Riya';'Helen';'Reena'}; Age = [25;30;35;40]; Height = [149;150;160;153]; Weight = [50;65;48;52]; Timer = datetime({'2023-01-01 09:00:00';'2023-01-01 09:30:00';'2023-01-01 10:00:00';'2023-01-01 11:00:00'}) T = table(Name,Age,Height,Weight,Timer)
When you execute it in matlab the table is created as shown below −
T = table(Name,Age,Height,Weight, Timer) T = 45 table Name Age Height Weight Timer _________ ___ ______ ______ ___________________ {'Siya' } 25 149 50 2023-01-01 09:00:00 {'Riya' } 30 150 65 2023-01-01 09:30:00 {'Helen'} 35 160 48 2023-01-01 10:00:00 {'Reena'} 40 153 52 2023-01-01 11:00:00
Let us now use the same table to create a timetable out of it.
The syntax of the function used is −
TT = table2timetable(T)
T is the table which is input to table2timetable() function. Let us execute the same in MAtlab
>> TT = table2timetable(T) TT = 44 timetable Timer Name Age Height Weight ____________________ _________ ___ ______ ______ 01-Jan-2023 09:00:00 {'Siya' } 25 149 50 01-Jan-2023 09:30:00 {'Riya' } 30 150 65 01-Jan-2023 10:00:00 {'Helen'} 35 160 48 01-Jan-2023 11:00:00 {'Reena'} 40 153 52 >>
Make use of timeseries2timetable() Function
The timeseries2timetable() function converts timeseries objects to timetables.
The syntax is as follows −
TT = timeseries2timetable(ts)
Here ts is the timeseries object.
The example below shows timeseries() that return timeseries object which we can later use inside timseries2timetable() function.
ts = timeseries(rand(5,1),[0 05 10 15 20])
The timeseries object is made up of 5 random number that are sampled at 5 second intervals.
The output when executed in matlab is −
>> ts = timeseries(rand(5,1),[0 05 10 15 20]) timeseries Common Properties: Name: 'unnamed' Time: [5x1 double] TimeInfo: [1x1 tsdata.timemetadata] Data: [5x1 double] DataInfo: [1x1 tsdata.datametadata] More properties, Methods >> ts.Time ans = 0 5 10 15 20 >>
The property ts.Time returns the time.
Let us now use the timeseries object in timeseries2timetable() function
TT = timeseries2timetable(ts)
When you execute in matlab the output is as follows −
>> TT = timeseries2timetable(ts) TT = 51 timetable Time Data ______ _______ 0 sec 0.81472 5 sec 0.90579 10 sec 0.12699 15 sec 0.91338 20 sec 0.63236 >>