readtimetable
Reads a file into a timetable, using a column or a time step for the row times.
Category: Language Fundamentals > Data Types
Syntax
TT = readtimetable(filename)
Uses the first datetime or duration column as row times.
TT = readtimetable(filename, 'TimeStep', dt)
Generates evenly spaced row times with step dt.
TT = readtimetable(filename, 'SampleRate', fs)
Generates row times from a sample rate.
Description
A timetable needs a time for every row. readtimetable takes it from the first column that holds datetime or duration values, or builds it from 'TimeStep' or 'SampleRate' when the file contains only measurements. The row times are stored apart from the variables and shown in the first column of the display.
Input arguments
filename- Name of the file to read.
'TimeStep'- A duration: the spacing between rows when the file has no time column.
'SampleRate'- Positive number of rows per second.
Output arguments
TT- Timetable whose remaining columns are the variables.
Example
fid = fopen('m.csv', 'w');
fprintf(fid, 'v,w\n1,5\n2,6\n');
fclose(fid);
TT = readtimetable('m.csv', 'TimeStep', seconds(1))
Output
TT = 2×2 timetable
Time v w
________ _ _
00:00:00 1 5
00:00:01 2 6
Notes
In MatLivre, a time column written as text is not converted automatically; use 'TimeStep' or 'SampleRate', or convert the column with datetime after readtable.