Using an If Statement inside a While Loop
13 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Joseph Cheng
2014 年 7 月 7 日
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 件のコメント
参考
カテゴリ
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!