Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.1.0 - 日本語


writetable

write a table to file

Syntax

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

Arguments

t

table

filename

name or path of file

Optional pairs OptionName, Value are:

"Delimiter", string

the column separator. Default value: ",".

"WriteRowNames", boolean

when %t, writes row names in the file (first column). Default value: %f.

"WriteVariableNames", boolean

when %t, writes variables names in the file (column names). Default value: %t.

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, OptionName, 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

History

バージョン記述
2024.0.0 Introduction in Scilab.
Report an issue
<< varfun Timeseries/Table writetimeseries >>

Copyright (c) 2022-2024 (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:
Thu May 22 12:57:16 CEST 2025