create a table from a file
t = readtable(filename) t = readtable(filename, opts) t = readtable(filename, OptionName, Value, ...) t = readtable(filename, opts, OptionName, Value, ...)
path or name of file to read
file import options obtained by detectImportOptions
Optional pairs OptionName, Value are:
extracts from the file only the data corresponding to the entered variable names.
the first column of the file will be stored in the RowNames property of the table t. Default value: %f.
output argument - table object.
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.
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 | ![]() | ![]() |
| Version | Description |
| 2024.0.0 | Introduction in Scilab. |