Changing numbers summed together in for loop

1 Ansicht (letzte 30 Tage)
C.G.
C.G. am 8 Jul. 2022
Beantwortet: KSSV am 8 Jul. 2022
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

Akzeptierte Antwort

KSSV
KSSV am 8 Jul. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by