csvwrite
Writes the values of a 2D matrix, m, to the file, f, where the values are comma-separated.
Syntax
csvwrite(f, m)
csvwrite(f, m, '-append', ...)
csvwrite(f, m, r, c, ...)
csvwrite(f, m, key-value, ...)
Inputs
- f
- File name or file handle.
- '-append'
- Optional keyword which appends matrix data to the output file, f. This argument is identical to the optional argument in dlmwrite.
- m
- Type: matrix
- r
- Optional argument specifying the number of lines containing only ',' at the beginning of the file f. This argument is identical to the optional argument in dlmwrite.
- c
- Optional argument specifying the number of lines of data in the output file f, which have ',' added to the start of the line. This argument is identical to the optional argument in dlmwrite.
- 'append', appendval
- Value for optional keyword 'append', specifying whether the data is appended to the output file f. Valid values for appendval are 'on' and 'off'. This argument is identical to the optional argument in dlmwrite.
- 'roffset', r
- Value for optional keyword 'roffset'. See r for details. This argument is identical to the optional argument in dlmwrite.
- 'coffset', c
- Value for optional keyword 'coffset'. See c for details. This argument is identical to the optional argument in dlmwrite.
- 'precision', p
- Value for the optional keyword 'precision', specifying the string that will be used by 'fprintf' for writing formatted matrix data or the number of significant digits. The default is the format specified in the application at the time of execution. This argument is identical to the optional argument in dlmwrite.
- 'newline', n
- Value for the optional keyword 'newline', specifying the delimiter between rows. Reserved values of 'pc', 'unix' or 'mac' use '\r\n', '\n' and '\r' as row delimiters, respectively. You can also specify any other delimiter using n. This argument is identical to the optional argument in dlmwrite.
Examples
f = fopen('Example1.csv', 'w');
csvwrite(f, rand(2,2))
0.60276,0.85795
0.54488,0.84725
csvwrite('Example2.csv', rand(2,2), 1, 2)
,,
,,0.54881,0.59284
,,0.71519,0.84427
csvwrite('Example1.csv', rand(3,2), 'append', 'on', 'roffset', 1, 'coffset', 1)
0.60276 0.85795
0.54488 0.84725
0.42365 0.62356
0.64589 0.38438
0.43759 0.29753
csvwrite('Example4.csv', rand(2,2), 'delimiter', ', ', 'newline', 'pc', 'precision', '%0.3f')
0.383, 0.478
0.792, 0.812