writetimeseries
write a timeseries to file
Syntax
writetimeseries(ts) writetimeseries(ts, filename) writetimeseries(..., OptionName, Value, ...)
Arguments
- ts
timeseries
- filename
file path. Accepted formats: ".xslx", ".csv", ".txt" and ".dat".
Optional pairs OptionName, Value are:
- "Delimiter", string
the column separator. Default value: ",".
- "WriteVariableNames", boolean
when %t, writes variables names in the file (column names). Default value: %t.
- "sheet", string or positive integer
specifies which sheet to write to.
If string: if the sheet name does not exist,
writetimeseriescreates a new sheet.If integer: select the sheet. If the index is greater than the number of sheets, then a new sheet is created with the name "Sheet_" + string(index).
Default: 1 (first sheet). Available option only is for Excel files.
- "range", string or positive integer
A string or 2x2 matrix specifying where to start writing data.
String formats: "A1:C10" (cell range), "A:C" (column range), "1:3" (row range), "B5" (first cell), "B" (first column), "3" (first row).
Matrix format: [row1 col1; row2 col2] where all values are positive integers >= 1.
Default: "". Available option only is for Excel files.
- "writemode", string
specifies the write mode:
"overwrite": Clears the sheet before writing data.
"append": Keeps existing data and adds new data at the specified range.
Default: data is written without clearing (preserves other cells). Available option only is for Excel files.
Description
The writetimeseries function writes a timeseries into a text file, where data are separated by comma (default value). It is possible to specify the delimiter to be applied: writetimeseries(ts, filename, "Delimiter", delim) Accepted file formats are .txt, .dat, .csv and .xlsx.
writetimeseries(ts) writes timeseries ts into the file timeseries.txt saved in TMPDIR.
writetimeseries(ts, filename, OptionName, Value) can be used to specify the column delimiter and to write the variable names into the file.
Examples
dt = [datetime(2022,1,10):caldays(1):datetime(2022,1,21)]'; hc = [13574; 13169; 11999; 12146; 15456; 10545; 11091; 21657; 11393; 10283; 10924; 16208]; hp = [13593; 15306; 16766; 15941; 14558; 13722; 18401; 14632; 14571; 14925; 14284; 15028]; ts = timeseries(dt, hc, hp, "VariableNames", ["Time", "HC", "HP"]); writetimeseries(ts, fullfile(TMPDIR, "data.txt")); r = readtimeseries(fullfile(TMPDIR, "data.txt"));
t = writetable(filename, "sheet", sheetName)
dt = datetime(2025, 5, 1, 8, 0, 0) + minutes([0; 5; 12; 20; 33; 47; 60]); id = ["S1"; "S1"; "S2"; "S1"; "S3"; "S2"; "S1"]; value = [10.2; 11.5; 9.8; 10.9; 12.1; 9.5; 11.0]; status = ["OK"; "OK"; "OK"; "WARN"; "OK"; "ERROR"; "OK"]; ts = timeseries(dt, id, value, status, "VariableNames", ["TIME", "ID", "VALUE", "STATUS"]) // ts = [7x3 timeseries] // // TIME ID VALUE STATUS // ___________________ ___ _____ ______ // // 2025-05-01 08:00:00 S1 10.2 OK // 2025-05-01 08:05:00 S1 11.5 OK // 2025-05-01 08:12:00 S2 9.8 OK // 2025-05-01 08:20:00 S1 10.9 WARN // 2025-05-01 08:33:00 S3 12.1 OK // 2025-05-01 08:47:00 S2 9.5 ERROR // 2025-05-01 09:00:00 S1 11 OK path = fullfile(TMPDIR, "data_ts.xlsx"); xlsxSheet(path, "create", "data"); // create "data" sheet writetimeseries(ts, path, "sheet", "data"); // write table in "data" sheet ts2 = readtimeseries(path, "sheet", "data") // ts2 = [7x3 timeseries] // // TIME ID VALUE STATUS // ___________________ ___ _____ ______ // // 2025-05-01 08:00:00 S1 10.2 OK // 2025-05-01 08:05:00 S1 11.5 OK // 2025-05-01 08:12:00 S2 9.8 OK // 2025-05-01 08:20:00 S1 10.9 WARN // 2025-05-01 08:33:00 S3 12.1 OK // 2025-05-01 08:47:00 S2 9.5 ERROR // 2025-05-01 09:00:00 S1 11 OK ts3 = readtimeseries(path, "sheet", "data", "range","A1:D5") // ts3 = [4x3 timeseries] // // TIME ID VALUE STATUS // ___________________ ___ _____ ______ // // 2025-05-01 08:00:00 S1 10.2 OK // 2025-05-01 08:05:00 S1 11.5 OK // 2025-05-01 08:12:00 S2 9.8 OK // 2025-05-01 08:20:00 S1 10.9 WARN
See also
- readtimeseries — create a timeseries from a file
- timeseries — create a timeseries - table with time as index
History
| バージョン | 記述 |
| 2024.0.0 | Introduction in Scilab. |
| 2026.1.0 |
|
| Report an issue | ||
| << writetable | Timeseries/Table | csvDefault >> |