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


readtable

create a table from a file

Syntax

t = readtable(filename)
t = readtable(filename, opts)

t = readtable(filename, Name, Value)
t = readtable(filename, opts, Name, Value)

Arguments

filename

path or name of file to read

format accepted: .txt, .dat and .csv

opts

file import options obtained by detectImportOptions

Name, Value

Name: 'VariableNames', Value: vector of strings: extracts from the file only the data corresponding to the entered variable names.

Name: 'ReadRowNames', Value: boolean (default value: %f): the first column of the file will be stored in the RowNames property of the table t.

t

table object.

Description

The readtable function creates a table from a file. Each column of file is stored in variables. If however the columns have no name, then the default variable names are used (["Var1", ..., "VarN"]). Accepted file formats are .txt, .dat or .csv.

readtable detects the format file thanks to detectImportOptions function. opts contains all information on the file.

To extract only the necessary variables (columns), use t = readtable(filename, "VariableNames", value).

t = readtable(filename, ..., "ReadRowNames", val) creates a table with row names, i.e, the first column of file is stored in RowNames property of t.

Examples

t = readtable(filename)

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 CSV file
writetable(t, fullfile(TMPDIR, "data.csv"))

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

t = readtable(filename, "VariableNames", value)

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 CSV file
writetable(t, fullfile(TMPDIR, "data.csv"))

// Read the CSV file with readtable
r = readtable(fullfile(TMPDIR, "data.csv"), "VariableNames", ["NameContinent", "NumberCountry", "Area"])

t = readtable(filename, "ReadRowNames", value)

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 CSV file
writetable(t, fullfile(TMPDIR, "data.csv"))

// Read the CSV file with readtable
r = readtable(fullfile(TMPDIR, "data.csv"), "ReadRowNames", %t)
r.Properties.RowNames

See also

  • writetable — write a table to file
  • table — create a table from variables
Report an issue
<< pivot Timeseries/Table readtimeseries >>

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