for loop and get previous value for current calculation
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Alex Mcaulley
2019-7-2
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
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!