This example shows how to export a dataset array from the MATLAB® workspace to a text or spreadsheet file.
load('hospital')The dataset array has 100 observations and 7 variables.
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.
export(hospital)
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 hospital with variable names suppressed
to a text file named NoLabels.txt.
export(hospital,'File','NoLabels.txt','WriteVarNames',false)
There are no variable names in the first line of the created
text file, NoLabels.txt.
Export hospital to a comma-delimited text
file, hospital.csv.
export(hospital,'File','hospital.csv','Delimiter',',')
Export hospital to an Excel® spreadsheet
named hospital.xlsx.
export(hospital,'XLSFile','hospital.xlsx')
By default, the first row of hospital.xlsx has
variable names, and the first column has observation names.