Main Content


Monte Carlo realization of tracking scenario

Since R2020a



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.

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.


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.

  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.

  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

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',false)

Enable parallel computing, specified as true or false. Using parallel computing requires a Parallel Computing Toolbox™ license and an open parallel pool.

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.

Version History

Introduced in R2020a