readmatrix
Create matrix array from file.
📝Syntax
M = readmatrix(filename)
M = readmatrix(filename, opts)
M = readmatrix(filename, opts, 'OutputType', type)
📥Input Arguments
Parameter Description
filename a string: an existing filename source.
opts DelimitedTextImportOptions object
type a string: 'double', 'single', 'char', 'string', 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'.
📤Output Arguments
Parameter Description
M a matrix.
📄Description

M = readmatrix(filename) creates a matrix array by importing column-oriented data from a text or spreadsheet file.

M = readmatrix(filename, opts) creates a matrix array using the settings defined in the opts import options object. The import options object allows you to customize how readmatrix interprets the file, offering greater control, improved performance, and the ability to reuse the configuration compared to the default syntax.

💡Examples
filename = [tempdir,'readmatrix_1.csv'];
Names = {'John'; 'Alice'; 'Bob'; 'Diana'};
Age = [28; 34; 22; 30];
Height = [175; 160; 180; 165];
Weight = [70; 55; 80; 60];
T = table(Names, Age, Height, Weight);
writetable(T, filename)
M = readmatrix(filename)
filename = [tempdir,'readmatrix_2.csv'];
M = magic(6);
writematrix(M, filename)
options = detectImportOptions(filename)
options.DataLines = [2 4];
M2 = readmatrix(filename, options, 'OutputType', 'int64')
M3 = readmatrix(filename, options, 'OutputType', 'char')
🔗See Also
writematrixdetectImportOptionswritetablereadtablefileread
🕔Version History
Version Description
1.10.0 initial version
Edit this page on GitHub