Write a matrix to a file
writematrix(
writes homogeneous array
A
)A
to a comma delimited text file. The file name is the workspace
variable name of the array, appended with the extension .txt
. If
writematrix
cannot construct the file name from the array name, then it
writes to the file matrix.txt
.
Each column of each variable in A
becomes a column in the output
file. The writematrix
function overwrites any existing file.
writematrix(
writes to a file with the name and extension specified by
A
,filename
)filename
.
writematrix
determines the file format based on the specified
extension. The extension must be one of the following:
.txt
, .dat
, or .csv
for
delimited text files
.xls
, .xlsm
, or .xlsx
for
Excel® spreadsheet files
.xlsb
for Excel spreadsheet files supported on systems with Excel for Windows®
writematrix(___,
writes
an array to a file with additional options specified by one or more
Name,Value
)Name,Value
pair arguments and can include any of the input arguments
in previous syntaxes.
To set the 'PreserveFormat'
name-value pair to
true
, you must set the 'UseExcel'
name-value pair
to true
.
There are some instances where the writematrix
function creates a
file that does not represent the input data exactly. You will notice this when you use the
readmatrix
function to read that file. The resulting data might not have the exact same format or
contents as the original array. If you need to save your array and retrieve it at a later time
to match the original array exactly, with the same data and organization, then save it as a
MAT-file. writematrix
writes inexact data in the following instances:
writematrix
writes out numeric data using long
g
format, and categorical or character data as unquoted text.
writematrix
writes out arrays that have more than two
dimensions as two dimensional arrays, with the trailing dimensions collapsed.
readmatrix
| writecell
| writematrix
| writetable
| writetimetable