readvars
Create variables by reading column-oriented data from a file.
📝Syntax
[Var1, Var2, ..., VarN] = readvars(filename)
[Var1, Var2, ..., VarN] = readvars(filename, opts)
📥Input Arguments
Parameter Description
filename a string: an existing filename source.
opts nelson.io.text.DelimitedTextImportOptions object
📤Output Arguments
Parameter Description
Var1, Var2, ..., VarN the columns of the file, each returned as a separate variable.
📄Description

[Var1, Var2, ..., VarN] = readvars(filename) creates variables by importing column-oriented data from a text or spreadsheet file.

Each column of the file is returned as a separate output variable. Text columns are returned as a cell array of character vectors and numeric columns as a column vector of type double, following the same conventions as readtable. Pass the 'TextType' name-value option with the value 'string' to return text columns as a string array instead.

Name-value options accepted by readtable, such as 'Range', are forwarded. Using 'Range' restricts the columns and rows returned as variables.

When fewer output variables are requested than the number of columns in the file, only the first columns are returned. Requesting more output variables than there are columns raises an error.

[Var1, Var2, ..., VarN] = readvars(filename, opts) uses the settings defined in the opts import options object. Any additional arguments are forwarded to readtable.

💡Examples
filename = [tempdir, 'readvars_1.csv']; Names = {'John'; 'Alice'; 'Bob'; 'Diana'}; Age = [28; 34; 22; 30]; Height = [175; 160; 180; 165]; T = table(Names, Age, Height); writetable(T, filename) [N, A, H] = readvars(filename)
🔗See Also
readtablereadmatrixreadcelldetectImportOptions
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub