readvars

Reads the columns of a file into separate variables.

Category: Data Import and Analysis > Data Import and Export

Syntax

[v1, v2, ...] = readvars(filename)

Returns one output per column.

[v1, v2, ...] = readvars(filename, opts)

Uses import options.

Description

readvars is like readtable followed by pulling each column out of the table, in one step. A header row, if present, supplies the names but they are not returned: the outputs are positional.

Input arguments

filename
Text or spreadsheet file name.

Output arguments

v1, v2, ...
One column vector per variable, in file order, each with the type detected for that column.

Example

Two numeric columns

fid = fopen('q.csv', 'w'); fprintf(fid, 'x,y\n1,2\n3,4\n'); fclose(fid);
[x, y] = readvars('q.csv');
x', y'
Output
ans = 1×2

     1     3
ans = 1×2

     2     4

Notes

In MatLivre, a text column comes back as NaN values; use readtable or readcell for files with text.

See also

readtable readmatrix readcell textscan