getDataValues
Class: io.reader
Namespace: io
Return data values for data imported using a custom reader
Syntax
dataVals = getDataValues(obj)
Description
Input Arguments
Custom data reader, specified as an object of a class that inherits from the io.reader
base class.
Example: MyCustomFileReader
Output Arguments
Signal values, returned as an array of numeric, enumeration, logical, or string
values. For scalar signals and wide signals, the first dimension of the array aligns
with time and must match the length of the time vector returned by getTimeValues
. For multidimensional signals, the last dimension aligns with
time and must match the length of the time vector returned by
getTimeValues
.
Examples
Write the function definition for the getDataValues
method to return signal values to use for data 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 the code for the getDataValues
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 getChildren
method reads the data from the
file using the readtable
function and returns an array of custom
reader objects for the top-level node that corresponds to the file and for each signal
in the file. Then, the getDataValues
method reads the data using the
readtable
function and selects the signal data to return for each
signal in the file using the VariableName
property of each custom
reader object.
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 dataVals = getDataValues(obj) dataVals = []; if ~isempty(obj.VariableName) t = readtable(obj.FileName); dataVals = t.(obj.VariableName); end end % ... end end
Write the function definition for the getDataValues
method to return signal values from a workspace variable. Specify the code executed by the
getDataValues
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
getDataValues
method returns the data from the d
field of the structure.
When the variable is an array of structures, the custom reader uses both the
getDataValues
and getChildren
methods to import the
data. 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
getDataValues
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 dataVals = getDataValues(obj) if isscalar(obj.VariableValue) dataVals = obj.VariableValue.d; elseif ~isempty(obj.ChannelIndex) varVal = obj.VariableValue(obj.ChannelIndex); dataVals = varVal.d; else dataVals = []; 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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)