To export a matrix to a CSV file in Matlab, you should use the csvwrite
function. The first argument to this function is the filename to write to, and the second argument is the matrix to be written.
Here is an example:
main.m116 chars4 lines
This will create a CSV file in the current working directory with the name output.csv
, containing the contents of the matrix M
.
Note that csvwrite
writes numeric data only, so if you have a matrix with mixed data types, you need to convert it to a numeric matrix first.
If you want to include row and/or column headers in your CSV file, you may need to use a more specialized function like writetable
or writecell
.
gistlibby LogSnag