dlmread

Reads a delimited numeric file into a matrix.

Category: Data Import and Analysis > Data Import and Export

Syntax

M = dlmread(filename)

Reads the file, guessing the delimiter.

M = dlmread(filename, delimiter)

Uses the given delimiter, for example ';' or '\t'.

M = dlmread(filename, delimiter, R, C)

Starts at zero-based row R and column C.

Description

When the delimiter is omitted it is inferred from the first line, so comma-, space-, tab- and semicolon-separated files all load without configuration. Lines shorter than the widest line are padded with zeros.

readmatrix is the modern replacement and also handles headers and missing values as NaN.

Input arguments

filename
Name of the file.
delimiter
Field separator. Escape sequences such as '\t' are understood.
R, C
Zero-based offsets of the first value to read.

Output arguments

M
Numeric matrix. Empty fields become 0.

Example

Semicolon-separated data

dlmwrite('s.txt', [1 2 3; 4 5 6], ';');
disp(fileread('s.txt'))
dlmread('s.txt', ';')
dlmread('s.txt', ';', 1, 1)
Output
1;2;3
4;5;6

ans = 2×3

     1     2     3
     4     5     6
ans = 1×2

     5     6

Notes

The rectangular range form dlmread(f, d, [r1 c1 r2 c2]) returns the whole file in MatLivre instead of the sub-block.

See also

dlmwrite csvread readmatrix importdata