for loop and get previous value for current calculation

1 visualización (últimos 30 días)
Guang Min Chin
Guang Min Chin el 2 de Jul. de 2019
Respondida: Alex Mcaulley el 2 de Jul. de 2019
Hi,
I have a question.
x2(t) = 0.01*(soc_ref-soc(t))+0.99*x2(t - delta_t)
I have all values for soc_ref, soc(t) and delta_t
Can anyone teach me how to do it in matlab?
Thank you.

Respuestas (1)

Alex Mcaulley
Alex Mcaulley el 2 de Jul. de 2019
x2 = zeros(numel(soc),1); %Preallocation
x2(1) = 0.01*(soc_ref-soc(1)); %Initialization
for t = 2:numel(soc)
x2(t) = 0.01*(soc_ref-soc(t))+0.99*x2(t - delta_t);
end

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by