writematrix

Write a matrix to a file.

Syntax

  • writematrix(M)

  • writematrix(M, filename)

  • writematrix(..., Name, Value)

Input argument

  • M - an numeric or logical matrix.

  • filename - a string: filename destination.

  • Name, Value - Name-Value Arguments

Description

writematrix writes an numeric matrix to an CSV format file.

writematrix does not support sparse matrices.

writematrix outputs numeric data in the long G format.

Available Name-Value Arguments

Name-value pairs must follow all other arguments.

The order of name-value pairs doesn't matter

Delimiter and QuoteStrings options only apply to delimited text files.

FileType: Specifies the type of output file

Syntax: 'FileType','text'

Supports delimited text files (.txt, .dat, .csv)

WriteMode: Controls how data is written to the file

Syntax: 'WriteMode', mode

Options:

'overwrite' (default) - Creates new file or replaces existing content

'append' - Adds data to end of existing file

If the target file doesn't exist, a new file will be created regardless of mode.

Delimiter: Defines the character used to separate fields

Syntax: 'Delimiter', delimiter

Available Delimiters: Only applicable for delimited text files.

Specifier
Alternative
Description

','

'comma'

Comma (default)

' '

'space'

Space character

'\t'

'tab'

Tab character

';'

'semi'

Semicolon

'|'

'bar'

Vertical bar

QuoteStrings: Controls text quoting behavior (Only applicable for delimited text files).

'QuoteStrings', option

with options

'minimal' (default) Quotes only text containing delimiters, line endings, or quotes.

'all' Quotes all text variables.

'none' Uses no quotes.

Example

A = [Inf, -Inf, NaN, 3];
filename = [tempdir(), 'writematrix_example.csv'];
writematrix(A, filename);
R = fileread(filename)

See also

readcell, csvwrite, dlmread, fileread.

History

Version
Description

1.10.0

initial version

Author

Allan CORNET

Last updated