Contenu principal

monteCarloRun

R2026b

Monte Carlo realization of tracking scenario

Description

recordings = monteCarloRun(scenario,numRuns) runs a tracking scenario multiple times and saves the running recording of every run. Each run, called a realization of the scenario, is with a different random seed.

example

recordings = monteCarloRun(scenario,numRuns,Name,Value) specifies options using one or more name-value pair arguments. Enclose each Name in quotes.

[recordings,rngs] = monteCarloRun(___) also returns the random number generator values at the beginning of each realization run.

Examples

collapse all

Load a prerecorded tracking scenario.

  load ATCScenario.mat scenario

Execute two Monte Carlo runs and display the running time. The actual running time will depend on the computation ability of your machine.

  tic
  recordings = monteCarloRun(scenario,2);
  disp("Time to run the scenarios: " + toc + " sec")
Time to run the scenarios: 153.2316 sec

Run the Monte Carlo simulations again using parallel computing.

  tic
  recordings = monteCarloRun(scenario,2,'UseParallel',true);
Starting parallel pool (parpool) using the 'local' profile ...
Connected to the parallel pool (number of workers: 6).
  disp("Time to run the scenarios in parallel: " + toc + " sec")
Time to run the scenarios in parallel: 118.1509 sec

Input Arguments

collapse all

Tracking scenario, specified as an M-element array of trackingScenario objects or an M-element cell array of trackingScenario objects.

Numbers of Monte Carlo runs, specified as a positive integer.

Name-Value Arguments

collapse all

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: monteCarloRun(sc,3,UseParallel="auto")

Option to perform computations in parallel using a parallel pool of workers, specified as one of these values:

  • "off" — Run in serial on the MATLAB client.

  • "auto" — Use a parallel pool if one is open or if MATLAB can automatically create one. If a parallel pool is not available, run in serial on the MATLAB client.

  • "on" — Use a parallel pool if one is open or if MATLAB can automatically create one. If a parallel pool is not available, throw an error.

If you do not have a parallel pool open and automatic pool creation is enabled, MATLAB opens a pool using the default cluster profile. To use a parallel pool to run computations in MATLAB, you must have Parallel Computing Toolbox™. For more information, see Run MATLAB Functions with Automatic Parallel Support (Parallel Computing Toolbox).

Before R2026b: To run in parallel, set UseParallel to true (1).

Data Types: char | string

Initial random seeds for obtaining repeatable results, specified as an integer in [0, 2^32-1] or an array of integers in [0, 2^32-1]. If specified as an integer, an array of seed values is randomly generated using the integer as an initial seed. If unspecified, the function uses the current random number generator to randomly generate an array of initial seeds.

Output Arguments

collapse all

Monte Carlo recordings of a tracking scenario, returned as a M-by-numRuns array of trackingScenarioRecording objects.

Random number generator values, returned as a M-by-numRuns array of structures. The fields of each structure are the same as the output of the rng function.

Extended Capabilities

expand all

Version History

Introduced in R2020a

expand all