FUNCTION REFERENCE
readmatrix
Read a numeric matrix from a text file.
Read a numeric matrix from a text file.
Syntax
A = readmatrix('data.csv')Syntax
A = readmatrix('data.csv', 'Delimiter', ';')Syntax
A = readmatrix('data.xlsx', 'Sheet', 'Results', 'Range', 'B2:D20')Syntax
A = readmatrix(filename, opts)Syntax
A = readmatrix(filename, opts, 'OutputType', type)With import options from detectImportOptions, every selected variable is read as a number (text that does not convert is an import error, NaN by default) and MissingRule, ImportErrorRule, DataLines or DataRange apply; 'OutputType' may be any numeric type or 'logical'.
Reads .csv, .txt or .dat files with numbers separated by comma, semicolon, tab or whitespace. 'FileType', 'text' allows other extensions. Spreadsheets (.xlsx, .xlsm, .xlsb, .xls, or 'FileType', 'spreadsheet') are read too: Sheet picks a sheet by name or 1-based index (default the first), Range picks a rectangle such as 'A1:C10' or a start cell such as 'B2'. Spreadsheet numbers and logical cells become doubles, every other cell NaN; without a Range, leading rows that hold no number (headers) are skipped.
Example
writematrix([1 2;3 4],'data.csv'); A = readmatrix('data.csv') % 2-by-2 numeric matrixDifferences from MATLAB: Text files detect leading text headers; retained fields must be numeric. No ranges or missing-data options there. Spreadsheet header detection only skips leading rows without numbers; dates read as their Excel serial numbers; no named ranges. An .xls workbook is read whole and is limited to 16777216 cells over all its sheets.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.