Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.0.0 - Français


writetable

write a table to file

Syntax

writetable(t)
writetable(t, filename)
writetable(..., Name, Value)

Arguments

t

table

filename

name or path of file

Name, Value

Name: 'Delimiter', Value: string: the column separator.

Name: 'WriteRowNames', Value: boolean (default value: %f): when %t, writes row names in the file (first column).

Name: 'WriteVariableNames', Value: boolean (default value: %t): when %t, writes variables names in the file (column names).

Description

The writetable function writes a table into a text file, where data are separated by comma. Accepted file formats are .txt, .dat or .csv.

writetable(t) writes table t into the file table.txt saved in TMPDIR.

writetable(t, filename, Name, Value) can be used to specify the column delimiter, to write the row names and the variable names into the file.

Examples

writetbale(t, filename) and writetbale(t, filename, 'WriteVariableNames', %f)

Code = ["AF"; "NA"; "OC"; "AN"; "AS"; "EU"; "SA"];
NameContinent = ["Africa"; "North America"; "Oceania"; "Antarctica"; "Asia"; "Europe"; "South America"];
Area = [30065000; 24256000; 7687000; 13209000; 44579000; 9938000; 17819000]; // in km2
NumberCountry = [54; 23; 14; %nan; 47; 45; 12]; 
LifeExpectancy = [60; 78; 75; %nan; 72; 75; 74]; // in years

t = table(Code, NameContinent, Area, NumberCountry, LifeExpectancy, ...
    "VariableNames", ["Code", "NameContinent", "Area", "NumberCountry", "LifeExpectancy"])

// Write the table in TXT file
writetable(t, fullfile(TMPDIR, "data.txt"))

// Read the TXT file with readtable
r = readtable(fullfile(TMPDIR, "data.txt"))

// Write the table in TXT file
writetable(t, fullfile(TMPDIR, "data.txt"), "WriteVariableNames", %f)

// Read the TXT file with readtable
r = readtable(fullfile(TMPDIR, "data.txt"))

t = readtable(filename, "WriteRowNames", %t)

x = ["a"; "b"; "c"; "d"; "e"];
x1 = [1:5]';
x2 = 2.*[1:5]';
t = table(x1, x2, "VariableNames", ["x1", "x2"]);
t.Row = x;

writetable(t, fullfile(TMPDIR, "data.csv"), "WriteRowNames", %t);
r = readtable(fullfile(TMPDIR, "data.csv"), "ReadRowNames", %t)

See also

  • readtable — create a table from a file
  • table — create a table from variables
Report an issue
<< varfun Timeseries/Table writetimeseries >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Oct 24 14:34:20 CEST 2023