フィルターのクリア

For Loop How to use previous calculated value in next iteration

2 ビュー (過去 30 日間)
Iris Willaert
Iris Willaert 2022 年 6 月 14 日
コメント済み: Iris Willaert 2022 年 6 月 20 日
I'm new to matlab and I want to create a loop where I re use the previous calculate value in the next iterations.
This is what I have right now but I have up until thirtyPerc so instead of writing it out I would like to create a for loop instead.
StartTime = Time(1,1);
OnePerc = StartTime + (PercentageTimeLeft * 10);
twoPerc = OnePerc + (PercentageTimeLeft * 10);
threePerc = twoPerc + (PercentageTimeLeft * 10);
PercentageIntervalTimes = [OnePerc,twoPerc,threePerc];
This is what I tried to do:
PercentageIntervalTimes = [];
OnePerc = StartTime + (PercentageTimeLeft * 10);
for i = 1:length(Time)
PercentageIntervalTimes = OnePerc (i +1 ) + (PercentageTimeLeft * 10);
end
Any help is very much appreciated!
Thanks!!

採用された回答

Torsten
Torsten 2022 年 6 月 14 日
PercentageIntervalTimes = StartTime + (1:length(Time))*(PercentageTimeLeft * 10);
No loop needed.
  1 件のコメント
Iris Willaert
Iris Willaert 2022 年 6 月 20 日
Thanks a lot! that also worked for me!

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

その他の回答 (1 件)

Ganesh
Ganesh 2022 年 6 月 14 日
This is something that you can do.
PercentageIntervalTimes = zeros(length(Time));
PercentageIntervalTimes(1) = StartTime + (PercentageTimeLeft * 10);
for i = 2:length(Time)
PercentageIntervalTimes(i) = PercentageIntervalTimes(i-1) + (PercentageTimeLeft * 10);
end
Kindly ensure that Time is an array-like data type.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by