Main Content

registerFileReader

Class: io.reader
Package: io

Register custom file reader for use in the Simulation Data Inspector

Since R2020b

Syntax

registerFileReader(obj,ext)

Description

registerFileReader(obj,ext) registers the custom file reader obj with the Simulation Data Inspector to use for files with extensions specified by ext. To use a custom file reader in the Simulation Data Inspector, you must register the reader at the start of each MATLAB® session.

Tip

To verify registration, use the io.reader.getRegisteredFileReaders method or the io.reader.getSupportedReadersForFile method.

Input Arguments

expand all

Custom data reader, specified as an object of a class that inherits from the io.reader base class.

Example: MyCustomFileReader

File extensions supported by custom reader, specified as a character vector, string, cell array of character vectors, or cell array of strings.

Example: [".xlsx" ".xls"]

Data Types: char | string | cell

Examples

expand all

This example shows how to register a custom file reader with the Simulation Data Inspector, verify registration was successful, and unregister a file reader.

Register the Custom File Reader

This example registers the file reader ExcelFirstColumnTime. For an example that shows how to author the custom file reader, see Import Data Using a Custom File Reader. As the name suggests, the custom file reader for this example supports Microsoft Excel™ files. Register the reader for the .xlsx and .xls extensions.

registerFileReader(ExcelFirstColumnTimeReader, [".xlsx" ".xls"]);

Verify Custom Reader Registration

To verify registration of a custom reader, you can use the io.reader.getRegisteredFileReaders method or the io.reader.getSupportedReadersForFile method.

The io.reader.getRegisteredFileReaders returns a string array that contains the names of all registered custom file readers.

io.reader.getRegisteredFileReaders
ans = 
"ExcelFirstColumnTimeReader"

You can also use the io.reader.getSupportedReadersForFile method to see all reader options for a specific file. The built-in option in the returned string array indicates that the Simulation Data Inspector has a built-in Excel file reader.

 io.reader.getSupportedReadersForFile('CustomFile.xlsx')
ans = 1x2 string
    "ExcelFirstColumnTimeReader"    "built-in"

Unregister a Custom File Reader

To unregister a custom file reader, use the unregisterFileReader method. All custom readers are unregistered when you close a MATLAB™ session.

unregisterFileReader(ExcelFirstColumnTimeReader, [".xlsx" ".xls"])

Version History

Introduced in R2020b