find

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

Get element or collection of elements from dataset

Description

example

[datasetOut,retIndex]=find(datasetIn,Name,Value,…) returns a Simulink.SimulationData.Dataset object and indices of the elements whose property values match the specified property names and values. Specify optional comma-separated pairs of Name,Value properties. Name is the property name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name-value pair properties in any order as Name1,Value1,...,NameN,ValueN.

example

[datasetOut,retIndex]=find(datasetIn,Name,Value,'-logicaloperator',…Name,Value,…) applies the logical operator to the matching property value. You can combine multiple logical operators. Logical operator can be one of:

  • -or

  • -and

If you do not specify an operation, the method assumes -and.

example

[datasetOut,retIndex]=find(datasetIn,'-regexp',Name,Value,…) matches elements using regular expressions as if the value of the property is passed to the regexp function as:

regexp(element.Name,Value)
The method applies regular expression matching to the name-value pairs that appear after -regexp. If there is no -regexp, the method matches elements as if the value of the property is passed as:

isequal(element.Name,Value)

For more information on -regexp, see -regexp With Multiple Block Paths.

-regexp With Multiple Block Paths

-regexp works with properties of type char. To specify multiple block paths, you can use Simulink.SimulationData.BlockPath and Simulink.BlockPath. For example, when a signal is logged in a referenced model, you can use Simulink.SimulationData.BlockPath to specify multiple block paths.

The method returns elements that contain a BlockPath property where one or more of the individual block paths match the specified Value path when you use:

  • -regexp with the BlockPath Name property.

  • Value as a character vector or scalar object of type Simulink.SimulationData.BlockPath with one block path

Input Arguments

expand all

SimulationData.Dataset object in which to search for matching elements.

Name of property to find in the element.

Value of property to find in the element.

Output Arguments

expand all

SimulationData.Dataset object that contains the elements that match the specified criteria. If there is no matching SimulationData.Dataset object, the returned SimulationData.Dataset object contains no elements.

Indices of the elements datasetIn that match the specified criteria.

Examples

expand all

Find a specific block path (specified by character vector) and port index.

dsOut = find(dsIn, 'BlockPath', 'vdp/x1', 'PortIndex', 1)

Find elements that have either name or propagated name as InValve.

dsOut = find(dsIn, 'Name', 'InValve', '-or', 'PropagatedName', 'InValve')
dsOut = find(dsIn, '-regex','Name', 'In*', '-or', …
                   '-regex','PropagatedName', 'In*')

Find and replace all elements containing specified_name with a new_name.

[dsOut,idxInDs] = find(ds, 'specified_name');
for idx=1: length(idxInDs)
  % process each element
   elm = get(dsOut, idx);
   elm.Name= 'New_Name'
   dsIn = setElement(dsIn, idxInDs(idx), elm);
end

Find all signals logged in a subSys using -regexp.

dsOut = find(dsIn, '-regexp', 'BlockPath', 'mdl/subSys/.*')

Find all signals logged in the Model block.

dsOut = find(dsIn, '-regexp', 'BlockPath', 'refmdl/ModelBlk')

Alternative

You can use curly braces to streamline indexing syntax to get an element in a dataset, instead of using find. 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 get method to get an element or collection of elements from a dataset.

Introduced in R2015b