How to write output Monte Carlo iterations from loop into an array matrix?

조회 수: 3 (최근 30일)
David
David 2014년 11월 19일
I wrote a code that generates Monte Carlo iterations as a loop. Currently I have it set so that the iterations which are vectors are output in a .txt file. However, after I run the model for N iterations (4 is used as an example below) the data is supposed to be output in a .txt file with N columns that is comma delimited. When I run the code there is no error, but the output is wrong. Where in the code am I going wrong? See below;
for i=1:4;
N=0.5+(rand()*1.5);
A=12+(rand()*8);
No=3600+(rand()*4200);
fa=(d15N-N)/(A-N); %d15N is an input parameter.
Na=(fa.*Nl); %N1 is an input parameter.
H=Na./No;
H(:,i)=[H(:,1)]; % I believe the problem is in this line or the next.
dlmwrite('output.txt',H,'delimiter',',');
end
The output of 4 iterations then looks like this (see attached .txt file and data pasted below). However there should not be values of zero and the first and fourth iteration should be different values. What am I doing wrong?
74372,0,0,74372 91387,0,0,91387 80975,0,0,80975 83102,0,0,83102 65531,0,0,65531 55236,0,0,55236 52848,0,0,52848 54308,0,0,54308 44347,0,0,44347 35402,0,0,35402 44722,0,0,44722 38421,0,0,38421 27692,0,0,27692 9766.3,0,0,9766.3 -1643.5,0,0,-1643.5 -7611.2,0,0,-7611.2 -8276.5,0,0,-8276.5 -8657.6,0,0,-8657.6 -9279.5,0,0,-9279.5 -9153.5,0,0,-9153.5 -10728,0,0,-10728 -7046.3,0,0,-7046.3 -1736,0,0,-1736 -4878.9,0,0,-4878.9 -809.23,0,0,-809.23 -5023.8,0,0,-5023.8 -1437.8,0,0,-1437.8 -569.45,0,0,-569.45 -4691.5,0,0,-4691.5 -6365.9,0,0,-6365.9 -2656.3,0,0,-2656.3 -26055,0,0,-26055 2161.1,0,0,2161.1 2253.5,0,0,2253.5 2741.1,0,0,2741.1 2636.1,0,0,2636.1 3694.2,0,0,3694.2 4836,0,0,4836 4117.3,0,0,4117.3 6000.1,0,0,6000.1 5258.9,0,0,5258.9 4372.5,0,0,4372.5 4228.9,0,0,4228.9 3991.5,0,0,3991.5 4827.6,0,0,4827.6 4636.3,0,0,4636.3 4181.4,0,0,4181.4 4576,0,0,4576 3939.3,0,0,3939.3 3715.5,0,0,3715.5 3052.4,0,0,3052.4 5184.8,0,0,5184.8 2300.9,0,0,2300.9 2397.9,0,0,2397.9 6933.8,0,0,6933.8 3999.3,0,0,3999.3 3073,0,0,3073 2191.9,0,0,2191.9 2036.5,0,0,2036.5 1879.1,0,0,1879.1 1438.7,0,0,1438.7 2276.9,0,0,2276.9 870.08,0,0,870.08 1327.2,0,0,1327.2 2666.4,0,0,2666.4 2644.7,0,0,2644.7 2966.1,0,0,2966.1 1790.7,0,0,1790.7 1895.8,0,0,1895.8 773.82,0,0,773.82 -218.2,0,0,-218.2 -488.01,0,0,-488.01 -3569.1,0,0,-3569.1 -5397.7,0,0,-5397.7 -4785.5,0,0,-4785.5 -3906.9,0,0,-3906.9 3595.8,0,0,3595.8 130.52,0,0,130.52

답변 (0개)

카테고리

Help CenterFile Exchange에서 Monte Carlo Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by