How to restart a for loop when a condition is met?
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all, I'm trying to restart a for loop when a specific condition is met. In particular this is my code:
for t=2:365;
R1=Rgas(t-tgas,mu,sigma)
ReliabilityGAS(t)=Rgas;
time(t)=t;
TIMELOST100=[ 56 64 70 120 230];
for j=1:length(TIMELOST100)
if t==(TIMELOST100(1,j))+2
tgas=t; %in this case Rgas has to be: Rgas(0,mu,sigma)
else
tgas=0; %in this case Rgas remains: Rgas(t,mu,sigma)
end
end
end
plot(time,ReliabilityGAS)
I wish every time that "tgas=t" , t in Rgas must restart from "t=2" . How can i do that?
Thanks for who will help me.
0 件のコメント
回答 (2 件)
Karthi Ramachandran
2019 年 9 月 27 日
編集済み: Karthi Ramachandran
2019 年 9 月 27 日
"I wish every time that "tgas=t" " is a condition check . but you have assigened tgas = t;
if t==(TIMELOST100(1,j))+2 && tgas == t
t = 2; %in this case Rgas has to be: Rgas(0,mu,sigma)
else
might help if tgas is calculated else where
0 件のコメント
darova
2019 年 9 月 27 日
Use while loop
t = 2;
while t <= 365;
R1=Rgas(t-tgas,mu,sigma)
ReliabilityGAS(t)=Rgas;
time(t)=t;
TIMELOST100=[ 56 64 70 120 230];
tgas = 0;
t = t + 1;
for j=1:length(TIMELOST100)
if t==(TIMELOST100(1,j))+2
t = 2;
tgas=t; %in this case Rgas has to be: Rgas(0,mu,sigma)
break
end
end
end
Pay attention that your loop is infinite (t will never be bigger than 58)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!