I was expecting that the following code would populate E with random 1's and 0's, but that does not happen. I cannot figure out why.
Pkg.add("StatsBase")
using StatsBase
function randomSample(items,weights)
sample(items, Weights(weights))
end
n = 10
periods = 100
p = [ones(n,periods)*0.5]
E = fill(NaN, (n,periods))
for i in 1:periods
for ii in 1:n
E(ii,i) = randomSample([1 0],[(p(ii,i)), 1 - p(ii,i)])
end
end
E
[ones(5, 10)]will give you anArrayofArray(s). In MATLAB, however, it makes no difference to add as many surrounding brackets as possible: the result will be just a matrix.fillto initializeE, why not do the same withp:? That is,p = fill(0.5, (n, periods)). This is more efficient (and reasonable) than first creating a matrix of ones, and then creating a second matrix by multiplying the first one with 0.5.