Hi, I'm new to matlab. I'm how do you run a time series 100x?
2 ビュー (過去 30 日間)
古いコメントを表示
trying to run a time series for a stage structure model with probability of survival randomly alternating between good (A_g) and bad (A_b) years (probability of a good year is 0.5). Then I need to run this 100 times.
P0_g=0.3;P0_b=0.1;P0=(P0_g+P0_b)/2; P1_g=0.7;P1_b=0.3;P1=(P1_g+P1_b)/2; P2_g=0.85;P2_b=0.75;P2=(P2_g+P2_b)/2; P3_g=0.99;P3_b=0.85;P3=(P3_g+P3_b)/2; m3=1.2;
n0=5;n1=7;n2=15;n3=35; N0=[n0,n1,n2,n3]';
A_g=[0 0 m3*P2_g m3*P3_g; P0_g 0 0 0; 0 P1_g 0 0; 0 0 P2_g P3_g];
A_b=[0 0 m3*P2_b m3*P3_b; P0_b 0 0 0; 0 P1_b 0 0; 0 0 P2_b P3_b];
N_ts =zeros(4,41); N_ts_total=zeros(1,41); lambda =zeros(1,41); N_ts(:,1) =N0;
%somehow need to get this stuff into the loop good = binornd(1, 0.5)
for i = 2 : 41 if(good == 1) A = A_g; else A = A_b; end N_ts(:,i) = A* N_ts (:, i-1); N_ts_total(1,i)= sum(N_ts (:,i)); lambda(1,i) = N_ts_total(1,i)/N_ts_total(1,i-1); end
0 件のコメント
採用された回答
Corey Silva
2017 年 10 月 5 日
編集済み: Corey Silva
2017 年 10 月 5 日
You can construct a for loop to run your code 100 times. A simple example of such a for loop is below
for j = 1:100
disp(j) % This will display the iteration count.
end
Place the code you want run 100 times inside of that for loop.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!