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

采纳的回答

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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by