Saving Values from a For Loop

13 ビュー (過去 30 日間)
Ryan Bingaman
Ryan Bingaman 2019 年 7 月 6 日
コメント済み: Ryan Bingaman 2019 年 7 月 6 日
Hello everyone,
Here is my "for" loop for a midterm project that I am working on. The outer "for" loop is supposed to run the inner "for" loop 100,000 times and save the resulting i value from the inner loop for each time the inner loop is completed. I need some assistance in editing my code to have it save my resultant i value into a vector every time the inner loop is completed. Thank You!
for j = 1:1:1e6
x = 260 + 6*randn(250,1);
i = 0;
o = 0;
for k = 1:length(x)
if x(k) < 260 && o == 0
i = i - (x(k)*100) - 175;
o = o + 100;
elseif x(k) > 265 && o == 100
i = i + (x(k)*100) - 175;
o = o - 100;
end
end
end

採用された回答

Walter Roberson
Walter Roberson 2019 年 7 月 6 日
Savedi(j) = i;
  1 件のコメント
Ryan Bingaman
Ryan Bingaman 2019 年 7 月 6 日
Thank you!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by