Write distributed data to an output location
write(location, D)
write(filepattern,D)
write(___,Name,Value)
write(
writes the values in the distributed array location
, D
)D
to files
in the folder location
. The data is stored in an
efficient binary format suitable for reading back using
datastore(location)
. If not distributed along
the first dimension, MATLAB® redistributes the data before writing, so that the
resulting files can be reread using
datastore
.
write(
uses the file extension from filepattern
,D
)filepattern
to determine
the output format. filepattern
must include a folder
to write the files into followed by a file name that includes a wildcard
*
. The wildcard represents incremental numbers
for generating unique file names, for example
write('folder/myfile_*.csv',D)
.
write(___,
specifies additional options with one or more name-value pair arguments
using any of the previous syntaxes. For example, you can specify the
file type with Name,Value
)'FileType'
and a valid file type
('mat'
, 'seq'
,
'text'
, or 'spreadsheet'
),
or you can specify a custom write function to process the data with
'WriteFcn'
and a function handle.
In some cases, write(location, D, 'FileType', type)
creates
files that do not represent the original array D
exactly. If
you use datastore(location)
to read the checkpoint files,
then the result might not have the same format or contents as the original
distributed table.
For the 'text'
and 'spreadsheet'
file
types, write
uses these rules:
write
outputs numeric variables using
longG
format, and categorical,
character, or string variables as unquoted text.
For non-text variables that have more than one column,
write
outputs multiple
delimiter-separated fields on each line, and constructs suitable
column headings for the first line of the file.
write
outputs variables with more than two
dimensions as two-dimensional variables, with trailing dimensions
collapsed.
For cell-valued variables, write
outputs the
contents of each cell as a single row, in multiple
delimiter-separated fields, when the contents are numeric,
logical, character, or categorical, and outputs a single empty
field otherwise.
Do not use the 'text'
or 'spreadsheet'
file types if you need to write an exact checkpoint of the distributed
array.
Use the write
function to create
checkpoints or
snapshots of your data as you work.
This practice allows you to reconstruct distributed arrays
directly from files on disk rather than re-executing all of the
commands that produced the distributed array.