writecell

Writes a cell array to a delimited text file or spreadsheet.

Category: Data Import and Analysis > Data Import and Export

Syntax

writecell(C, filename)

Writes C to filename; the format follows the extension (.txt, .csv, .xlsx).

writecell(C, filename, 'Delimiter', d)

Uses delimiter d between fields in a text file.

Description

Each cell becomes one field and each row of the cell array one line. Numbers are written in text form and character vectors as they are, so a mixed cell array such as {1, 'x'; 2, 'y'} produces a mixed file. For .csv the default delimiter is a comma.

If the file already exists it is overwritten. readcell reads the same layout back.

Input arguments

C
Cell array whose cells hold scalars or text.
filename
Output file name.
'Delimiter'
Field separator for text files, such as ',', ';' or 'tab'.

Example

Mixed data to CSV

C = {1, 'x'; 2, 'y'};
writecell(C, 'cell_demo.csv');
type cell_demo.csv
writecell(C, 'cell_demo2.csv', 'Delimiter', ';');
type cell_demo2.csv
Output

1,x
2,y


1;x
2;y

See also

readcell writematrix writetable writelines