Hi, I'm new to matlab. I'm how do you run a time series 100x?

조회 수: 1 (최근 30일)
jarvla
jarvla 2017년 10월 2일
편집: Corey Silva 2017년 10월 5일
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

채택된 답변

Corey Silva
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개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by