Function Reference: readtimetable

datatypes: tt = readtimetable (filename)
datatypes: tt = readtimetable (filename, Name, Value)

Read a file into a timetable, in the MATLAB-compatible form.

tt = readtimetable (filename) reads filename as readtable reads it, taking the file to carry a header row of names and then one row per row, and turns the result into a timetable. Text files (.txt, .csv, .dat) and spreadsheets (.ods, .fods, .xlsx, .xlsm) are supported, and 'FileType' overrides what the extension says.

The first datetime or duration variable becomes the row times and the row dimension takes its name, which is what MATLAB does and what makes a file written by writetimetable come back as it went out. 'RowTimes' names a different variable, by name or by index. A file with no such variable cannot be read as a timetable.

A column written in the RFC 9557 form, 2024-03-09T22:00:00-05:00[America/New_York], is recognised and comes back as a zone-aware datetime with its zone and its side of any daylight-saving fold intact. That is what writetimetable writes for zoned row times; see deviation D7 in that method’s help for why. A column MATLAB wrote is read as MATLAB reads it, so a bare wall clock comes back unzoned, exactly as it does there.

Every Name-Value option of readtable is accepted and behaves as it does there, with two exceptions. 'ReadRowNames' and 'RowNamesColumn' are refused: a timetable labels its rows by time and by nothing else, so a file whose rows are named is read with readtable.

TimeStep and SampleRate are not stored in the file and are worked out again from the row times. No file MATLAB can read carries an event table, so the result never has one; use ods2timetable for that.

See also: timetable.writetimetable, readtable, ods2timetable, csv2timetable, timetable

Source Code: readtimetable

writetimetable writes a zoned datetime in the RFC 9557 form, which carries both the offset and the zone name, so readtimetable returns the timetable that was written rather than an unzoned shadow of it.

 t = datetime (2024, 3, 9, 22, 0, 0, 'TimeZone', 'America/New_York') ...
     + hours ((0:2)');
 TT = timetable (t, (1:3)', 'VariableNames', {'reading'});
 fname = [tempname(), '.csv'];
 writetimetable (TT, fname);
 type (fname);
t,reading
2024-03-09T22:00:00-05:00[America/New_York],1
2024-03-09T23:00:00-05:00[America/New_York],2
2024-03-10T00:00:00-05:00[America/New_York],3
 readtimetable (fname)
ans =
  3x1 timetable

             t              reading    
    ____________________    _______    

    09-Mar-2024 22:00:00          1    
    09-Mar-2024 23:00:00          2    
    10-Mar-2024 00:00:00          3
 delete (fname);