simple loop option to reduce code
1 次查看(过去 30 天)
显示 更早的评论
Hi, Can anyone suggest a neat way to simply the following code.
T=0.25;
t1=-3*T/12:.001:T/12;
t2=t1(end):.001: t1(end) + T/3;
t3=t2(end):.001: t2(end) + T/3;
t4=t3(end):.001: t3(end) + T/3;
t5=t4(end):.001: t4(end) + T/3;
t6=t5(end):.001: t5(end) + T/3;
---------------------------------------------------
I'm intending to use a for loop as follow but, I'm getting an error message
for r=2:6
t(r)=t(r-1)(end):t1(end):.001: t(r-1)(end) + T/3;
end
0 个评论
采纳的回答
kei hin
2013-12-10
T=0.25;
t{1}=-3*T/12:.001:T/12;
for r=2:6
t{r} = t{r-1}(end):.001: t{r-1}(end) + T/3;
end
更多回答(2 个)
Andrei Bobrov
2013-12-10
编辑:Andrei Bobrov
2013-12-10
T = .25;
n = 6;
tt = -3*T/12:.001:T/12;
Time1 = bsxfun(@plus,tt,diff(tt([1,end]))*(0:n-1)');
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!