Using an If Statement inside a While Loop
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a code I am writing in which I need to incorporate an If statement inside of a While loop. I want my code to run equations a - d when a(2) > d and when a(2) <= d I want to pull that value out and put it into a separate vector. The issue I am having is that my loop stops after finding only one value of a(2) <= d, where I would like to find and pull out (place into separate vector) all values when a(2) <= d. Can anyone tell me what I am missing?
Pulsepileup.m :
a = rand(2,1)
b = round(a(1)*80+20)
c = find(energies100 == b)
d = spectrum100(c)
while a(2) > d
run pulsepileup.m
if a(2) <= d
x = b
end
end
Thank you!
0 commentaires
Réponses (1)
Joseph Cheng
le 7 Juil 2014
what you're missing is
x=[];
while a(2) > d
run pulsepileup.m
if a(2) <= d
x = [x b];
end
end
your original code stores the one value for when a(2)<=d. with the addition i made it'll concatenate to x when the condition is true.
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!