getName
Class: io.reader
Namespace: io
Syntax
retName = getName(obj)
Description
returns the name to use in the Simulation Data
Inspector for a signal or hierarchical node in data imported from the workspace or a
file.retName
= getName(obj
)
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: MyCustomFileReader
Output Arguments
retName
— Signal name
character array
Signal name used by the Simulation Data Inspector, returned as a character array.
Examples
Get Names for Data Imported from File
Write the function definition for the getName
method
to return names for signals imported from a file. The custom reader in this example
imports the data from the file with a hierarchical structure, treating the file as the top
node. Specify code for the getName
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. For an example that shows the complete class definition and import workflow, see
Import Data Using Custom File Reader.
In this example, the getName
and getChildren
methods work together to assign the appropriate name to each imported signal. The
getChildren
method reads the data from the file using the
readtable
function. The method then constructs a cell array that
contains a custom reader object for each signal read from the file.
The getName
method uses the FileName
property
of the custom reader object to return the file name as the name for the top-level node.
The getName
method uses the VariableName
property
to return the signal name extracted from the file to use as the signal name for each
imported signal.
classdef ExcelFirstColumnTimeReader < io.reader methods % ... function childObj = getChildren(obj) childObj = {}; if isempty(obj.VariableName) t = readtable(obj.FileName); vars = t.Properties.VariableNames; vars(1) = []; childObj = cell(size(vars)); for idx = 1:numel(vars) childObj{idx} = ExcelFirstColumnTimeReader; childObj{idx}.FileName = obj.FileName; childObj{idx}.VariableName = vars{idx}; end end end function retName = getName(obj) if isempty(obj.VariableName) fullName = obj.FileName; splitName = split(fullName,["\" "/"]); retName = splitName{end}; else retName = obj.VariableName; end % ... end end
Get Names for Data Imported from Workspace
Write the function definition for the getName
method
to return signal names for data imported from the workspace. Specify code for the
getName
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
). When the variable to import is a scalar structure, the
getName
method returns the value in the n
field of
the imported structure.
When the variable is an array of structures, the custom reader uses both the
getName
and getChildren
methods to return signal
names. The getChildren
method creates a custom reader object for each
structure in the array and sets the ChannelIndex
property to
identify the index of the signal data within the array. Then, the
getName
method uses the ChannelIndex
property
value to select the appropriate structure from the VariableValue
property value, which is the array of structures.
classdef SimpleStructReader < io.reader properties ChannelIndex end methods % ... function childObj = getChildren(obj) childObj = {}; if ~isscalar(obj.VariableValue) && isempty(obj.ChannelIndex) numChannels = numel(obj.VariableValue); childObj = cell(numChannels,1); for idx = 1:numChannels childObj{idx} = SimpleStructReader; childObj{idx}.VariableName = sprintf('%s(%d)',obj.VariableName,idx); childObj{idx}.VariableValue = obj.VariableValue; childObj{idx}.ChannelIndex = idx; end end end function retName = getName(obj) if isscalar(obj.VariableValue) retName = char(obj.VariableValue.n); elseif ~isempty(obj.ChannelIndex) varVal = obj.VariableValue(obj.ChannelIndex); retName = char(varVal.n); else retName = 'Signal Array'; 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 (한국어)