This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

get

Class: Simulink.SimulationData.Dataset
Package: Simulink.SimulationData

Get element or collection of elements from dataset

Syntax

element = get(dataset,index)
element = get(dataset,name)
element = get(dataset,{name})

Description

element = get(dataset,index) returns the element corresponding to the index. The getElement method uses the same syntax and behavior as the get method.

element = get(dataset,name) returns the element whose name matches name. When name is in a cell array, return the index of the element whose name matches name.

element = get(dataset,{name}) returns a single element if only one element name matches, a SimulationData.Dataset if multiple elements with this name exist.

If you use Log Dataset data to file to create the MAT-file, use getAsDatastore for fast access to the data.

Input Arguments

expand all

The data set from which to get the element.

Index value of element to get. The index reflects the index value of a data set element.

Name for a data set element, specified as:

  • A character array reflecting the name of the data set element

  • A cell array containing one character vector. To return a SimulationData.Dataset object that can contain one element, use this format. Consider this form when writing scripts.

Output Arguments

expand all

The element that the get method finds.

  • If index is the first argument after the data set, the method returns the element at the index.

  • If name is the first argument after the data set:

    • If the method finds one element, it returns the element.

    • If the method finds more than one element, return a Dataset that contains the elements.

    • If the method does not find an element, it returns an empty object.

Examples

expand all

Access Simulink.SimulationData.Dataset elements in the top model of the ex_bus_logging model. The signal logging dataset is topOut.

open_system(docpath(fullfile(docroot,'toolbox','simulink',...
'examples','ex_bus_logging')));
open_system(docpath(fullfile(docroot,'toolbox','simulink',...
'examples','ex_mdlref_counter_bus')));
sim('ex_bus_logging')
topOut
topOut = 

  Simulink.SimulationData.Dataset
  Package: Simulink.SimulationData

  Characteristics:
              Name: 'topOut'
    Total Elements: 4

  Elements:
    1: 'COUNTERBUS'
    2: 'OUTPUTBUS'
    3: 'INCREMENTBUS'
    4: 'inner_bus'

  -Use get or getElement to access elements by index, name or 
   block path.
  -Use addElement or setElement to add or modify elements.

  Methods, Superclasses

Access the element at index if the first argument is a numeric value.

el = logsout.get(1);

Access the element whose name matches name.

el = logsout.get('name');

Return a dataset if the first argument is a cell array with a character vector as the first element.

ds = logsout.get({'my_name'}); 

Alternatives

You can use curly braces to streamline indexing syntax to get an element in a dataset, instead of using get or getElement. The index must be a scalar that is not greater than the number of elements in the variable. For example, get the second element of the logsout dataset.

logsout{2}

Also, you can use the find method to get an element or collection of elements from a dataset.

Introduced in R2011a