Changing numbers summed together in for loop

1 回表示 (過去 30 日間)
C.G.
C.G. 2022 年 7 月 8 日
回答済み: KSSV 2022 年 7 月 8 日
I have a code below, which minuses one value from another and divides it by the defined time interval (dt).
This code works for the first iteration, as the time interval is 1, so it would be: Q_i+1 - Q_i.
However, I want this to change with the time interval, so that the next iteration does Q_i+2 - Q_i, then Q_i+3 -Q_i etc up until dt = 30.
Can anybody help me change the code so it does this?
dt = [1:1:30]; %increasing time intervals of interest up to Trw
nt = 28594;
for a = 1:length(dt)
Qtime = (Q_ots(2:end)- Q_ots(1:end-1))/dt(:,a)
Qt(a) = sum(Qtime)/nt
end

採用された回答

KSSV
KSSV 2022 年 7 月 8 日
t = 1:1:30; %increasing time intervals of interest up to Trw
nt = 28594;
Qt = 0 ;
for a = 1:length(dt)
Qtime = (Q_ots(a+1)- Q_ots(1)/t(a) ;
Qt = QT+Qtime/nt ;
end

その他の回答 (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