This is probablly a silly question, and I'm missing the obvious, but how does one save the output of monte carlo iterations, without overwiritng the previous iteration? For example, one MC run returns the following:
ExpoStart(column)=row; % a row vector
I have a long code subject to a Monte Carlo that looks something like this:
nsamples=500; %500 monte carlo iterations
for i=1:nsamples
hlm = unifrnd(6,9.7); %1st variable going through MC
hlfm = unifrnd(3.9,5.9); %2nd variable going through MC
for column = (1:ncolumn) %start of pharma-mondel loop
for t = 1:timesteps
% here is a long pharma-mondel, not included for simplicity
end
ExpoStart(column)=row; % pharma-mondel output from one iteration of monte carlo
end %end of pharma-mondel loop
%this is were I beleive there should be a line saving the "ExpoStart(column)" for each of...
%the 500 iteration of the monte carlo, but I'm not sure how to do this with without overwriting the last iteration.
end
I imagine the output being 500 rows of ExpoStart(column), with each row being output from sequential monte carlo iterations....but how to code this...?
Thanks you in advance for any suggestions/ help you maybe able to provide!

 Respuesta aceptada

David Fletcher
David Fletcher el 7 de Abr. de 2021

0 votos

Change the line
ExpoStart(column)=row
to
ExpoStart(i,column)=row
And (I think) it will do what you want. There is an argument for pre-allocating the array in advance rather than have Matlab continually grow it on the fly, but if it's not really big, I wouldn't worry over it too much.

3 comentarios

Wesser
Wesser el 8 de Abr. de 2021
Unfortunalty this isn't working. If I make the change to:
ExpoStart(i,column)=row
Then all the rows befor the final row are zero. Perhaps there is something wrong about my monte carlo setup, but I thought that at least that part of the code I had gotten right, so I don't understand the rows of zeros.
I added my actual code, if you have any time to help slueth this out. It seems like there needs to be an additional line added after the completion of each monte carlo iteration...possibly around L249 in the attached.
Thank you again for any thoughts you might have on this!
David Fletcher
David Fletcher el 8 de Abr. de 2021
OK - now I see. You virtually already had it in the code you provided. The line close to the end just needs to be changed to:
MC_ExpoStart(i,:)=ExpoStart(column)
And (I think) this will give you the rows where each column in the serum matrix change from being non-zero over the five iterations. I've run it and it seems to work as far as I can see.
Wesser
Wesser el 8 de Abr. de 2021
Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Preguntada:

el 7 de Abr. de 2021

Comentada:

el 8 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by