Main Content

matlab.io.datastore.FileWritable class

Package: matlab.io.datastore

Add file writing support to datastore

Since R2020a

Description

matlab.io.datastore.FileWritable is an abstract mixin class that adds file writing support to custom datastores by adding support for the writeall method.

To use this mixin class, you must inherit from the matlab.io.datastore.FileWritable class and the matlab.io.Datastore base class. Use this syntax as the first few lines in your class definition file:

classdef MyDatastore < matlab.io.Datastore & ....
                       matlab.io.datastore.FileWritable
  ...
end
To add support for file writing to your custom datastore, you must follow these requirements:

  • Inherit from an additional class matlab.io.datastore.FileWritable.

  • Initialize the properties SupportedOutputFormats and DefaultOutputFormat.

  • Implement a write method if the datastore writes data to a custom format.

  • Implement a getFiles method if the datastore does not have a Files property.

  • Implement a getFolders method if the datastore does not have a Folders property.

  • The output location is validated as a string. If your datastore requires further validation, you must implement a validateOutputLocation method.

  • If the datastore is meant for files that require multiple reads per file, then you must implement the methods getCurrentFilename and currentFileIndexComparator.

  • Optionally, inherit from another class matlab.io.datastore.FoldersPropertyProvider to add support for a Folders property (and thus the FolderLayout name-value pair of writeall). If you do this, then you can use the populateFoldersFromLocation method in the datastore constructor to populate the Folders property.

  • To add support for the 'UseParallel' option of writeall, you must subclass from both matlab.io.datastore.FileWritable and matlab.io.datastore.Partitionable and implement a partition method in the subclass that supports the syntax partition(ds,'Files',index).

The matlab.io.datastore.FileWritable class is a handle class.

Properties

expand all

List of writeable formats, returned as a string vector. This property lists all possible output formats that can be used with writeall. See Initialize Properties of Custom Datastore for an example of initializing this property in a subclass.

Attributes:

GetAccess
public
SetAccess
public
Constant
true
Abstract
true

Data Types: string

Default output format, returned as a string scalar. This property gives the output format to use with writeall when none is specified. See Initialize Properties of Custom Datastore for an example of initializing this property in a subclass.

Attributes:

GetAccess
public
SetAccess
public
Constant
true
Abstract
true

Data Types: string

Methods

expand all

Examples

collapse all

If you are authoring a custom datastore class that subclasses from matlab.io.datastore.FileWritable to add file writing capabilities, then you need to initialize the properties SupportedOutputFormats and DefaultOutputFormat in the subclass.

For example, the subclass in Develop Custom Datastore for DICOM Data initializes these properties as:

properties (Constant)
  SupportedOutputFormats = ...
    [matlab.io.datastore.ImageDatastore.SupportedOutputFormats, "dcm"];
  DefaultOutputFormat = "dcm";
end

"dcm" is a custom format that is also set to be the default, but the datastore also supports all supported output formats of ImageDatastore.

Version History

Introduced in R2020a