Main Content

Export Dataset Arrays

This example shows how to export a dataset array from the MATLAB® workspace to a text or spreadsheet file.

Load sample data.


The dataset array has 100 observations and 7 variables.

Export to a text file.

Export the dataset array, hospital, to a text file named hospital.txt. By default, export writes to a tab-delimited text file with the same name as the dataset array, appended by .txt.


This creates the file hospital.txt in the current working folder, if it does not previously exist. If the file already exists in the current working folder, export overwrites the existing file.

By default, variable names are in the first line of the text file. Observation names, if present, are in the first column.

Export without variable names.

Export hospital with variable names suppressed to a text file named NoLabels.txt.


There are no variable names in the first line of the created text file, NoLabels.txt.

Export to a comma-delimited format.

Export hospital to a comma-delimited text file, hospital.csv.


Export to an Excel spreadsheet.

Export hospital to an Excel® spreadsheet named hospital.xlsx.


By default, the first row of hospital.xlsx has variable names, and the first column has observation names.

See Also


Related Examples

More About