generateSimulationEnsemble
Generate ensemble data by running a Simulink model
Syntax
Description
[
generates data for a simulation ensemble by running the Simulink® model specified by status
,E
] = generateSimulationEnsemble(simin
)simin
. This input argument is
a vector of Simulink.SimulationInput
objects that also specifies
other parameters to change from simulation to simulation to generate the ensemble.
The function writes the simulation data log files to the current folder. Each file
contains the corresponding Simulink.SimulationInput
object and all
the variables that the model is configured to log for the simulation. The output
arguments indicate whether any simulations generate errors and return any such
errors. Use simulationEnsembleDatastore
to create an ensemble
datastore for interacting with the simulated data.
For general information about data ensembles, see Data Ensembles for Condition Monitoring and Predictive Maintenance.
[
uses additional options specified by one or more status
,E
] = generateSimulationEnsemble(simin
,location
,Name,Value
)Name,Value
pair arguments.
Examples
Generate Ensemble of Fault Data
Generate a simulation ensemble datastore of data representing a machine operating under fault conditions by simulating a Simulink® model of the machine while varying a fault parameter.
Load the Simulink model. This model is a simplified version of the gear-box model described in Using Simulink to Generate Fault Data. For this example, only one fault mode is modeled, a gear-tooth fault.
mdl = 'TransmissionCasingSimplified';
open_system(mdl)
The gear-tooth fault is modeled as a disturbance in the Gear Tooth fault
subsystem. The magnitude of the disturbance is controlled by the model variable ToothFaultGain
, where ToothFaultGain = 0
corresponds to no gear-tooth fault (healthy operation). To generate the ensemble of fault data, you use generateSimulationEnsemble
to simulate the model at different values of ToothFaultGain
, ranging from -2 to zero. This function uses an array of Simulink.SimulationInput
objects to configure the Simulink model for each member in the ensemble. Each simulation generates a separate member of the ensemble in its own data file. Create such an array, and use setVariable
to assign a tooth-fault gain value for each run.
toothFaultValues = -2:0.5:0; % 5 ToothFaultGain values for ct = numel(toothFaultValues):-1:1 simin(ct) = Simulink.SimulationInput(mdl); simin(ct) = setVariable(simin(ct),'ToothFaultGain',toothFaultValues(ct)); end
For this example, the model is already configured to log certain signal values, Vibration
and Tacho
(see Save Signal Data Using Signal Logging (Simulink)). generateSimulationEnsemble
further configures the model to:
Save logged data to files in the folder you specify.
Use the
timetable
format for signal logging.Store each
Simulink.SimulationInput
object in the saved file with the corresponding logged data.
Specify a location for the generated data. For this example, save the data to a folder called Data
within your current folder. The indicator status
is 1 (true) if all the simulations complete without error.
mkdir Data location = fullfile(pwd,'Data'); [status,E] = generateSimulationEnsemble(simin,location);
[19-Aug-2023 15:38:21] Running simulations... [19-Aug-2023 15:38:29] Completed 1 of 5 simulation runs [19-Aug-2023 15:38:33] Completed 2 of 5 simulation runs [19-Aug-2023 15:38:37] Completed 3 of 5 simulation runs [19-Aug-2023 15:38:41] Completed 4 of 5 simulation runs [19-Aug-2023 15:38:46] Completed 5 of 5 simulation runs
Inside the Data
folder, examine one of the files. Each file is a MAT-file containing the following MATLAB® variables:
SimulationInput
— TheSimulink.SimulationInput
object that was used to configure the model for generating the data in the file. You can use this to extract information about the conditions (such as faulty or healthy) under which this simulation was run.logsout
— ADataset
object containing all the data that the Simulink model is configured to log.PMSignalLogName
— The name of the variable that contains the logged data ('logsout'
in this example). ThesimulationEnsembleDatastore
command uses this name to parse the data in the file.SimulationMetadata
— Other information about the simulation that generated the data logged in the file.
Now you can create the simulation ensemble datastore using the generated data. The resulting simulationEnsembleDatastore
object points to the generated data. The object lists the data variables in the ensemble, and by default all the variables are selected for reading. Examine the DataVariables
and SelectedVariables
properties of the ensemble to confirm these designations.
ensemble = simulationEnsembleDatastore(location)
ensemble = simulationEnsembleDatastore with properties: DataVariables: [4x1 string] IndependentVariables: [0x0 string] ConditionVariables: [0x0 string] SelectedVariables: [4x1 string] ReadSize: 1 NumMembers: 5 LastMemberRead: [0x0 string] Files: [5x1 string]
ensemble.DataVariables
ans = 4x1 string
"SimulationInput"
"SimulationMetadata"
"Tacho"
"Vibration"
ensemble.SelectedVariables
ans = 4x1 string
"SimulationInput"
"SimulationMetadata"
"Tacho"
"Vibration"
You can now use ensemble
to read and analyze the generated data in the ensemble datastore. See simulationEnsembleDatastore
for more information.
Input Arguments
simin
— Simulation configurations
vector of Simulink.SimulationInput
objects
Simulation configurations, specified as a vector of Simulink.SimulationInput
(Simulink)
objects. The simulation configurations specify parameters for each generated
member of the ensemble, such as:
Simulink model to run
Values of model variables
Block parameters
Model initial state
Thus, for example, you can create a vector of
Simulink.SimulationInput
objects in which all simulation
configurations are identical except for the parameters that model the
presence and severity of faults in your system. You can then use the vector
to generate an ensemble of simulated data representing a range of healthy
and faulty operating conditions.
location
— Folder path
pwd
(default) | string | character vector
Folder path at which to store simulation data, specified as a string or a
character vector. If you do not provide location
, the
function uses the current folder (the path returned by
pwd
).
In the specified folder, the function writes one MAT-file per simulation. Each file includes the following variables:
SimulationInput
— TheSimulink.SimulationInput
object that was used to configure the model for generating the data in this file. You can use this object to extract information about the conditions (such as faulty or healthy) under which this simulation was run.SimulationMetadata
— Other information about the simulation that generated the logged data in the file.A
Dataset
object containing all the signal and state data that the Simulink model is configured to log. By default, this variable is calledlogsout
, but the name is configurable in the model.PMSignalLogName
— The name of the variable that contains the logged data ('logsout'
by default). ThesimulationEnsembleDatastore
command uses this name to parse the data in the file.
For more information about data logging, see Save Signal Data Using Signal Logging (Simulink).
Example: pwd + "\simResults"
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'UseParallel',true
UseParallel
— Whether to run simulations in parallel
false
(default) | true
Whether to run simulations in parallel, specified as the
comma-separated pair consisting of 'UseParallel'
and:
false
— Do not run simulations in parallel.true
— Use a parallel pool to run multiple simulations in parallel (requires Parallel Computing Toolbox™).
ShowProgress
— Whether to display simulation progress
true
(default) | false
Whether to display simulation progress in the MATLAB® command window, specified as the comma-separated pair
consisting of 'ShowProgress'
and:
true
— Display a simulation progress line each time an individual simulation run completes.false
— Do not display simulation progress.
Output Arguments
status
— Simulation error status
logical
Simulation error status, returned as a logical value:
1 (true) if all simulations run to completion without error
0 (false) otherwise
E
— Simulation errors
structure array
Simulation errors, returned as a structure array with fields:
'SimulationInput'
—Simulink.SimulationInput
for the simulation run that generated the error'ErrorDiagnostic'
— String containing the error
Extended Capabilities
Automatic Parallel Support
Accelerate code by automatically running computation in parallel using Parallel Computing Toolbox™.
To run in parallel, set the 'UseParallel'
option to
true.
Version History
Introduced in R2018a
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)