To use arrayfun() to run a Monte-Carlo simulation of 100,000 replications and compute the probability of an event, you can follow these steps:
main.m168 chars9 lines
arrayfun()
to call this function 100,000 times and store the results in a vector.main.m54 chars2 lines
The @(x)
syntax creates an anonymous function that calls one_replication()
for each value of x
in the range 1 to 100,000.
results
vector.main.m29 chars2 lines
Since each element of results
is either 0 or 1, the mean of the vector gives the proportion of times the event occurred, which is an estimate of the true probability.
Note that you will need to replace the comment in the one_replication()
function with the actual simulation code.
gistlibby LogSnag