writetable(T)
writetable(T, filename)
writetable(..., Name, Value)
| Parameter | Description |
|---|---|
| T | A table to be written to a file. |
| filename | A string specifying the destination filename. |
writetable(T) writes the table T to a comma-delimited text file.
The file name is derived from the table's workspace variable name, with the .txt extension appended.
If the file name cannot be derived from the table name, the default file name table.txt is used.
Output formats supported:
To specify the file name explicitly, use writetable(T, filename). The file format is determined by the file extension:
Additional options: Use writetable(..., Name, Value) for customization:
false).
'text'
or
'xml'
).true).
'overwrite'
or
'append'
).
','
,
'\t'
, etc.).
'minimal'
,
'all'
, or
'none'
).
'Attribute'
).
'row'
).
'table'
).JSON files (.json extension or 'FileType', 'json'): the table is written as a JSON array with one object per row; keys are the variable names.
true).true); with false they are written as null.T = table([1; 2; 3], {'A'; 'B'; 'C'}, [10.5; 20.7; 30.2], 'VariableNames', {'ID', 'Name', 'Value'});
T.Value_Attribute = {'High'; 'Medium'; 'Low'};
% Basic usage - write to text file
writetable(T)
% Write to specific CSV file with custom delimiter
writetable(T, 'data.csv', 'Delimiter', ';')
% Write to XML with custom node names
writetable(T, 'data.xml', 'RowNodeName', 'record', 'TableNodeName', 'dataset')
% Append to existing file with row names
writetable(T, 'data.txt', 'WriteMode', 'append', 'WriteRowNames', true)
T = table([1; NaN], ["a"; missing], [true; false], 'VariableNames', {'x', 'name', 'ok'}); f = [tempdir, 'writetable_json.json']; writetable(T, f); fileread(f) writetable(T, f, 'PrettyPrint', false, 'PreserveInfAndNaN', false); fileread(f)
| Version | Description |
|---|---|
| 1.10.0 | Initial version. |
| 2.0.0 | JSON files: FileType json, PrettyPrint and PreserveInfAndNaN. |