Changing numbers summed together in for loop
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (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!