summation of answers received in a "for" loop
2 次查看(过去 30 天)
显示 更早的评论
I want to collect the output of a for loop in both summation of the answers and the answers received in each stage of this process. In specific case, I want to have summation of the 5 answers obtained from below code. here "t_layer(i)" give me the answer obtained in each stage. I wanted to have summatuon of them in t_totall. But the code which I have written only gives me the last loop as t_total.
t_liner=1.5
for i=1:5
if rem(i,2)==0
t1(i)=i+3;
t2(i)=0;
elseif rem(i,2)==1
t2(i)=i-1;
t1(i)=0;
end
t_layer(i)=t1(i)+t2(i);
t_total=t_liner+t1(i)+t2(i);
Hope to have your instruction on this matter.
0 个评论
采纳的回答
KSSV
2021-9-3
t_liner=1.5 ;
t1 = zeros(5,1) ;
t2 = zeros(5,1) ;
t_layer = zeros(5,1) ;
t_total = zeros(5,1) ;
for i=1:5
if rem(i,2)==0
t1(i)=i+3;
t2(i)=0;
elseif rem(i,2)==1
t2(i)=i-1;
t1(i)=0;
end
t_layer(i)=t1(i)+t2(i);
t_total(i)=t_liner+t1(i)+t2(i);
end
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!