VOOZH about

URL: https://www.geeksforgeeks.org/matlab/how-to-export-a-matrix-as-a-csv-file-in-matlab/

⇱ How To Export a Matrix as a CSV File in MATLAB? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How To Export a Matrix as a CSV File in MATLAB?

Last Updated : 28 Apr, 2025

A CSV file - Comma Separated File, as the name suggests, is a file that stores data delimited by a ' , '. In MATLAB, there is a simple way of exporting a matrix to a csv file. The writematrix() function is used to write a matrix into any desired file type. The syntax is

writematrix(<matrix_name>, "filename.extension");

This will create a new file in the current directory with the matrix stored in it. Let us see the same for csv files with various examples. Now, the following is a 2x5 matrix, and we will export it to a csv file named matrix.csv.

Example 1:

Output:

The created csv file: 

👁 Image
 

Let's export a 4x5 matrix with floating point data to csv file.

Example 2:

Output:

The new csv file would be:

👁 Image
 
Comment