FUNCTION REFERENCE
textscan
Read delimited text into a cell array.
Read delimited text into a cell array.
Syntax
C = textscan(fid, formatSpec)Syntax
C = textscan(str, formatSpec)Syntax
C = textscan(fid, formatSpec, N, 'Delimiter', d, 'HeaderLines', n, 'CollectOutput', tf, 'EndOfLine', eol)formatSpec uses %f, %d, %n (numbers) and %s (text), with %* to skip a field.
Numbers give a column vector and text a cell column; an empty number field is NaN.
Line breaks end a record; missing fields on that line are NaN for numbers and
empty character arrays for text. EndOfLine sets the line ending ('\n', '\r\n', '\r', or '').
A field that does not convert ends the scan, and so does the end of the data in
the middle of a record; the fields read before are kept, so the columns can
differ in length. At the end of the data the file position is at the end and
feof is true, so a while ~feof(fid) loop ends.
For files opened in UTF-8 text mode ('rt'), a leading UTF-8 BOM is skipped.
Example
C = textscan('1 2 3 4', '%f %f'); C{2} % [2; 4]Differences from MATLAB: %d gives double, not int32; other conversions and options
are not supported; Delimiter takes a character vector, each character a delimiter.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.