Main Content


Create new ensemble datastore from subset of existing ensemble datastore



sens = subset(ens,idx) creates a new ensemble datastore sens from a subset of the existing ensemble datastore ens by extracting the ensemble members that correspond to the indices in idx.

Use subset when you want to perform ensemble operations on a specific ensemble member or group of ensemble members, and when using a sequence of read commands with the source ensemble does not provide the ensemble members that you want to process. For example, you can use subset to:

  • Extract only ensemble members with a specific fault condition.

  • Perform preliminary processing and feature generation on a smaller ensemble that contains a similar distribution of conditions to the larger ensemble.

  • Extract a single ensemble member with specific characteristics to isolate and explore member behavior.

Specify which members you want to extract using the index vector idx. You can then operate on your extracted ensemble using the same techniques that you use for any data ensemble.


collapse all

Extract the ensemble member that you identify from an ensemble datastore and use a single read command to obtain the contents.

For this example, use the following code to create a simulationEnsembleDatastore object using data previously generated by running a Simulink® model at a various fault values (see generateSimulationEnsemble). The ensemble includes simulation data for five different values of a model parameter, ToothFaultGain. Because of the volume of data, the unzip operation takes a few minutes.

ens = simulationEnsembleDatastore(pwd,'logsout')
ens = 
  simulationEnsembleDatastore with properties:

           DataVariables: [5x1 string]
    IndependentVariables: [0x0 string]
      ConditionVariables: [0x0 string]
       SelectedVariables: [5x1 string]
                ReadSize: 1
              NumMembers: 5
          LastMemberRead: [0x0 string]
                   Files: [5x1 string]

ems_nm = ens.NumMembers
ems_nm = 5

The ensemble contains five files.

Extract the fourth ensemble member into a new, single-member ensemble sens.

idx = 4;
sens = subset(ens,idx);
sens_nm = sens.NumMembers
sens_nm = 1

sens contains one member. View the file name to confirm the member index.

ans = 

Reset sens to the first member and read the contents.

m4 = read(sens)
m4=1×5 table
    PMSignalLogName           SimulationInput                   SimulationMetadata                   Tacho                Vibration     
    _______________    ______________________________    _________________________________    ___________________    ___________________

      {'logsout'}      {1x1 Simulink.SimulationInput}    {1x1 Simulink.SimulationMetadata}    {20213x1 timetable}    {20213x1 timetable}

m4 contains the data for the extracted member.

Create a simulation ensemble datastore from a subset of an existing simulation ensemble datastore.

Create a simulationEnsembleDatastore object using data previously generated by running a Simulink® model at various fault values.

ens = simulationEnsembleDatastore(pwd,'logsout');
ens_nm = ens.NumMembers
ens_nm = 5

The ensemble contains five files. View the file names.

ans = 5x1 string

Extract the first, third, and fifth files into a new ensemble.

idx = [1 3 5];
sens = subset(ens,idx);
sens_nm = sens.NumMembers
sens_nm = 3

The new ensemble contains three members. View the file names.

ans = 3x1 string

The new ensemble contains the three files that you indexed.

Input Arguments

collapse all

Source ensemble datastore from which to extract members, specified as a fileEnsembleDatastore or a simulationEnsembleDatastore object. For an example of extracting a member from an ensemble datastore, see Extract Specific Member from Ensemble Datastore.

Indices of source ensemble members to extract, specified as a numeric vector, an integer vector, or a logical vector. The number of elements in the vector must not exceed the number of members in ens. For numeric or integer vectors, all indices must be positive. For logical vectors, the number of elements must be equal to the number of ensemble members in ens. For an example of creating and using an index vector, see Create Subset of Ensemble Datastore.

Output Arguments

collapse all

Extracted ensemble datastore, returned as a fileEnsembleDatastore or a simulationEnsembleDatastore object.

Introduced in R2021a