Function Reference: csv2timetable

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

Read a comma-separated-value (CSV) file into a timetable.

tt = csv2timetable (filename) reads the CSV file named by filename into a timetable. filename may be a character vector, a cellstr, or a string scalar.

A file written by timetable2csv carries the package’s own header block, which names and types every variable and tags the leading column of row times with their type, their TimeZone where they have one, and their Format. Such a file comes back as the timetable it was written from: the row times keep their type, zone and format exactly, and the row dimension keeps its name.

Any other CSV file is read as csv2table reads it, and its first datetime or duration variable becomes the row times, the row dimension taking that variable’s name. A file with no such variable cannot be read as a timetable.

Every Name-Value option of csv2table 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 csv2table.

TimeStep and SampleRate are not stored in the file and are worked out again from the row times, so a regular timetable comes back regular. A CSV file carries no event table, so 'Events' of the result is always empty even when the timetable that was written had one; use timetable2ods and ods2timetable to keep events.

See also: timetable.timetable2csv, csv2table, ods2timetable, readtimetable, timetable

Source Code: csv2timetable

A timetable written by timetable2csv comes back whole: the row times keep their type, their time zone and their display format, and the row dimension keeps its name.

 t = datetime (2024, 3, 9, 22, 0, 0, 'TimeZone', 'America/New_York') ...
     + hours ((0:3)');
 TT = timetable (t, (1:4)', 'VariableNames', {'reading'});
 TT.Properties.DimensionNames{1} = 'Stamp';
 fname = [tempname(), '.csv'];
 timetable2csv (TT, fname);
 csv2timetable (fname)
ans =
  4x1 timetable

           Stamp            reading    
    ____________________    _______    

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