How to use For loop
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I am doing a geology assignment and would love some assistance with the for loop function. I have to refine the ages of some terraces and to do that I need to do a for loop where I tell Matlab that the fan is younger than T5 and T3 to get an output age that follows stratagraphic order. So far this is what I have: ageT3=normrnd(16500,4850,10000,1) ageT5=normrnd(14100,4600,10000,1) ageFan=normrnd(9850,1750,10000,1) for i=1:10000 T3(i)=datasample(ageT3,1); T5(i)=datasample(ageT5,1); Fan(i)=datasample(ageFan,1); if Fan(i)<T5(i)<T3(i) Ages(i)=unifrnd(Fan(i),T3(i) else Ages(i)=NaN; end end
I hope this makes sense.I dont use Matlab often and I have no idea what I am doing.
Thanks
0 件のコメント
回答 (1 件)
Arthi Sathyamurthi
2021 年 5 月 24 日
Expressions like a<b<c are interpreted as (a<b)<c which turns out to compare the logical result from a<b (either 0 or 1) with c. To test if the value variable fan is less than T3 and T5 use the condition as (Fan(i)<T5(i)) && (Fan(i)<T3(i))
Your snippet would be like,
for i=1:10000
T3(i)=datasample(ageT3,1);
T5(i)=datasample(ageT5,1);
Fan(i)=datasample(ageFan,1);
if (Fan(i)<T5(i)) && (Fain(i)<T3(i))
Ages(i)=unifrnd(Fan(i),T3(i))
else
Ages(i)=NaN;
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!