how do I go about creating and storing data for a monte carlo simulation?

조회 수: 8 (최근 30일)
Fede C 2018 London
Fede C 2018 London 2019년 10월 22일
편집: Fede C 2018 London 2019년 10월 22일
Hi all,
This is my ham-fisted attempt to assign memory for the above. Let's say that I want my simulated data to be normally distributed random numbers (they're not, but right now I just care about having a structure in place) arranged in 3 series of 226 observations. So I create a cell that contains the 226x3 (empty, for now) arrays. Let's say I want 4 simulations, so 4 four of those (that's rubbish,but, again, just to keep things simple).
Then I create a 3 dimensional array of the right dimensions with said normal, random data. At this point I ought to extract each 226x3 lots of normal random data and shove it in the cell. Presumably, at that point, I can just put my model in that second loop and do what I need to do.
I can't seem to be able to do the extracting bit. M only contains the last 226x3 block from the 3 dimensional array (rather than all 4).
clc;
clear;
par.muorig = 5; %mean
par.sigmaorig = 5; %stdev
Nsim = 4; % number of simulations
Lseries= 226;
M=cell(4,1);
%allocate memory for matrices-which perhaps I can store in cells
for imatrices=1:Nsim
M{imatrices}=zeros(Lseries,3);
end
for isim= 1:Nsim
data(:,:,isim)=normrnd(par.muorig,par.sigmaorig,Lseries,3);
ff=1
for rr=1:Nsim
M=data(:,:,isim); %pull out each array and shove it in the cells
ff=ff+1
%my model here
end
end
Any suggestions on how to do this? I look forward to hearing from you!

답변 (1개)

Fede C 2018 London
Fede C 2018 London 2019년 10월 22일
편집: Fede C 2018 London 2019년 10월 22일
I think this does it. For those who might need to do something similar:
clc;
clear;
par.muorig = 5;
par.sigmaorig = 5;
Nsim = 4; % number of simulations
Lseries= 226; %sample size
M=cell(4,1);
for imatrices=1:Nsim
M{imatrices}=zeros(Lseries,3);
for isim= 1: Nsim
M{isim}=normrnd(par.muorig,par.sigmaorig,Lseries,3);
end
%my model here
end

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by