| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Statistics Toolbox |
| Contents | Index |
| Learn more about Statistics Toolbox |
Write dataset array to file
export(DS,'file',filename)
export(DS)
export(DS,'file',filename,'Delimiter',delim)
export(DS,'XLSfile',filename)
export(DS,'XPTFile',filename)
export(DS,...,'WriteVarNames',false)
export(DS,...,'WriteObsNames',false)
export(DS,'file',filename) writes the dataset array DS to a tab-delimited text file, including variable names and observation names, if present. If the observation names exist, the name in the first column of the first line of the file is the first dimension name for the dataset (by default, 'Observations'). export overwrites any existing file named filename.
export(DS) writes to a text file whose default name is the name of the dataset array DS appended by '.txt'. If export cannot construct the file name from the dataset array input, it writes to the file 'dataset.txt'. export overwrites any existing file.
export(DS,'file',filename,'Delimiter',delim) writes the dataset array DS to a text file using the delimiter delim. delim must be one of the following:
' ' or 'space'
'\t' or 'tab'
',' or 'comma'
';' or 'semi'
'|' or 'bar'
export(DS,'XLSfile',filename) writes the dataset array DS to an Microsoft® Excel® spreadsheet file, including variable names and observation names (if present). You may also specify the 'Sheet' and 'Range' parameter name/value pairs, with parameter values as accepted by the xlsread function.
export(DS,'XPTFile',filename) writes the dataset array DS to a SAS XPORT format file. When writing to an XPORT format file variables must be scalar valued. export saves observation names to a variable called obsnames unless the WriteObsNames parameter described below is false. The XPORT format restricts the length of variable names to eight characters; longer variable names will be truncated.
export(DS,...,'WriteVarNames',false) does not write the variable names to the text file. export(DS,...,'WriteVarNames',true) is the default, writing the names as column headings in the first line of the file.
export(DS,...,'WriteObsNames',false) does not write the observation names to the text file. export(DS,...,'WriteObsNames',true) is the default, writing the names as the first column of the file.
In some cases, export creates a text file that does not represent A exactly, as described below. If you use dataset to read the file back into MATLAB, the new dataset array may not have exactly the same contents as the original dataset array. Save A as a MAT-file if you need to import it again as a dataset array.
export writes out numeric variables using long g format, and categorical or character variables as unquoted strings. For non-character variables with more than one column, export writes out multiple delimiter-separated fields on each line, and constructs suitable column headings for the first line of the file. export writes out both the time and the data fields of timeseries variables, as separate columns. export writes out variables that have more than two dimensions as a single empty field in each line of the file. For cell-valued variables, export writes out the contents of each cell only when the cell contains a single row, and writes out a single empty field otherwise.
In some cases, export may create a file that cannot be read back into MATLAB using dataset. Writing a dataset array that contains a cell-valued variable whose cell contents are not scalars will result in a mismatch in the file between the number of fields on each line and the number of column headings on the first line. Writing a dataset array that contains a cell-valued variable whose cell contents are not all the same length will result in a different number of fields on each line in the file.
Move data between external text files and dataset arrays in the MATLAB workspace:
A = dataset('file','sat2.dat','delimiter',',')
A =
Test Gender Score
'Verbal' 'Male' 470
'Verbal' 'Female' 530
'Quantitative' 'Male' 520
'Quantitative' 'Female' 480
export(A(A.Score > 500,:),'file','HighScores.txt')
B = dataset('file','HighScores.txt','delimiter','\t')
B =
Test Gender Score
'Verbal' 'Female' 530
'Quantitative' 'Male' 520 ![]() | explike | exppdf | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |