supportsVariable
Class: io.reader
Namespace: io
Syntax
supported = supportsVariable(obj,var)
Description
returns the logical value supported
= supportsVariable(obj
,var
)supported
that indicates whether the custom
workspace reader specified by obj
supports the variable specified by
var
. When you write a custom workspace reader, you must implement the
supportsVariable
method in the class definition.
Input Arguments
obj
— Custom data reader
io.reader
subclass object
Custom data reader, specified as an object of a class that inherits from the io.reader
base class.
Example: MyCustomReader
var
— Workspace variable to import
variable
Workspace variable to import, specified as a variable in the base workspace.
Example: myVar
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| char
| string
| struct
| table
| cell
| categorical
| datetime
| duration
| calendarDuration
| fi
Complex Number Support: Yes
Output Arguments
supported
— Whether custom reader supports variable
logical
Whether the custom reader supports variable, returned as a logical value.
Examples
Determine Whether Custom Reader Supports Variable
Write the function definition for the
supportsVariable
method to return true only when the reader can import
the input variable. Specify the code for the supportsVariable
method in
the class definition file.
This example does not show a complete class definition. All custom readers must define
behavior for the getName
,
getTimeValues
, and getDataValues
methods, and workspace data readers need to define the supportsVariable
method. For an example that shows the complete class
definition and import workflow for a workspace data reader, see Import Workspace Variables Using a Custom Data Reader.
The custom reader in this example imports a structure or an array of structures from
the workspace. The structures must contain fields for the signal data
(d
), the time data (t
), and the signal name
(n
). The supportsVariable
method returns true when:
The input variable is a structure or array of structures that contains the appropriate fields.
The
n
field of each structure contains a character array or string to represent the signal name.The
t
field of each structure is a column vector of double data.The
d
field of each structure contains numeric data and is the same size as thet
field, meaning there is a sample value for each time step.
classdef ExcelFirstColumnTimeReader < io.reader methods % ... function supported = supportsVariable(~, val) % Support structure with fields t (time), d (data), and n (name) supported = ... isstruct(val) && ... isfield(val,'t') && ... isfield(val,'d') && ... isfield(val,'n'); if supported for idx = 1:numel(val) varName = val(idx).n; time = val(idx).t; varData = val(idx).d; % Name must be string or character array if ~ischar(varName) && ~isstring(varName) supported = false; % Time must be double column vector elseif ~isa(time,'double') || ~iscolumn(time) supported = false; % Data size must match time size else timeSz = size(time); dataSz = size(varData); if ~isnumeric(varData) || ~isequal(dataSz, timeSz) supported = false; end end end end end % ... end end
Version History
Introduced in R2020b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)