<< writematrix Spreadsheet

writetable


Write table to file.


Syntax


writetable(T)
writetable(T, filename)
writetable(..., Name, Value)

Input argument


T

A table to be written to a file.

filename

A string specifying the destination filename.

Description


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:

Example


Examples demonstrating various usages of

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)

See also


table.

History


Version Description
1.10.0 Initial version.

Author


Allan CORNET

<< writematrix Spreadsheet