Main Content

supportsReading

Class: Simulink.data.adapters.BaseMatlabFileAdapter
Package: Simulink.data.adapters

Check if external file has read attributes

Syntax

tf = supportsReading(adapterObj,sourceFile)

Description

tf = supportsReading(adapterObj,sourceFile) checks if the external source file has read attributes. The default implementation uses the isSourceValid method to check that the file exists and is in the correct format, then checks that the file has read attributes. You can override this method so that multiple adapters can read the same file type but with different headers.

Custom file adapters must define behavior for the getAdapterName, getSupportedExtensions, and getData methods. In addition, you can choose to override the isSourceValid, supportsReading, getSectionNames, getCurrentChecksum, open, and close methods.

Input Arguments

expand all

Custom file adapter, specified as an object of a class that derives from the Simulink.data.adapters.BaseMatlabFileAdapter base class.

Example: myCustomFileAdapter

External source file, specified as a character array or string.

Output Arguments

expand all

True or false result, returned as a 1 or 0 of data type logical or an array of logical values.

Examples

expand all

Write the function definition for the supportsReading method to determine if the external source file supports reading.

In this example, the supportsReading method reads data from an XML file with a format similar to the following.

<customerData>
<x>10</x>
<y>15</y>
</customerData>

The method checks that XML file has read attributes and that it contains the appropriate header information for this adapter.

function retVal = supportsReading(adapterObj, source)
    retVal = false;
    % Call base class method to ensure file has read attributes
    if supportsReading@Simulink.data.adapters.BaseMatlabFileAdapter(adapterObj,source)
        dom = xmlread(source);
        tree = dom.getFirstChild;
        if strcmp(tree.getNodeName, "customerData")
            retVal = true;
        end
    end
end

Version History

Introduced in R2022b