matlab.io.datastore.FileWritable - Add file writing support to datastore - MATLAB (original) (raw)
Main Content
Namespace: matlab.io.datastore
Add file writing support to datastore
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 thematlab.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 theFolderLayout
name-value pair ofwriteall
). If you do this, then you can use thepopulateFoldersFromLocation method in the datastore constructor to populate theFolders
property. - To add support for the
'UseParallel'
option ofwriteall
, you must subclass from bothmatlab.io.datastore.FileWritable
andmatlab.io.datastore.Partitionable
and implement apartition
method in the subclass that supports the syntaxpartition(ds,'Files',index)
.
The matlab.io.datastore.FileWritable
class is a handle class.
Properties
List of writable 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
Examples
If you are authoring a custom datastore class that subclasses frommatlab.io.datastore.FileWritable
to add file writing capabilities, then you need to initialize the properties SupportedOutputFormats
andDefaultOutputFormat
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 ofImageDatastore
.
Version History
Introduced in R2020a