Main Content

supportsFile

Class: io.reader
Package: io

Return logical indication of whether custom reader supports file

Syntax

supported = supportsFile(obj,filename)

Description

supported = supportsFile(obj,filename) returns the logical value supported that indicates whether the custom reader specified by obj supports the file specified by filename. The Simulation Data Inspector always checks whether a file is supported based on the file extension alone. Use the supportsFile method to specify code for additional support validation.

Input Arguments

expand all

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

Example: MyCustomFileReader

Name of file to import, specified as a character vector or string.

Example: 'MyDataFile.xlsx'

Data Types: char | string

Output Arguments

expand all

Whether custom reader supports file, returned as a logical value.

Examples

expand all

Write the function definition for the supportsFile method to determine whether the custom reader supports the data in the file. This example does not show a complete class definition. All custom readers must define behavior for the getName, getTimeValues, and getDataValues methods. For an example that shows the complete class definition and import workflow, see Import Data Using a Custom File Reader.

In this example, the supportsFile method reads the data in the file using the readtable function and checks that the file contains data in more than one column.

classdef ExcelFirstColumnTimeReader < io.reader
  methods
    % ...

    function childObj = getChildren(obj)
      try
        t = readtable(filename);
        supported = height(t) > 0 && numel(t.Properties.VariableNames) > 1;
      catch
        supported = false;
      end
    end
  % ...
  end
end
Introduced in R2020b