Changing numbers summed together in for loop

1 visualización (últimos 30 días)
C.G.
C.G. el 8 de Jul. de 2022
Respondida: KSSV el 8 de Jul. de 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

Respuesta aceptada

KSSV
KSSV el 8 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by