How to use For loop
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Arthi Sathyamurthi
il 24 Mag 2021
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 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!