Do I use the "for loop" correct or efficiently?
1 次查看(过去 30 天)
显示 更早的评论
Is there a better way or more efficient?
n = 3500;
t_s = 0;
t_f = 3500;
t = linspace(t_s,t_f,n);
a = zeros(1,n);
for i = 1:1800
a(i) = 50/3.6;
for n = 1800:3000
a(i) = 90/3.6;
for n = 3000:3500
a(i) = 0;
end
end
end
0 个评论
采纳的回答
per isakson
2021-8-28
编辑:per isakson
2021-8-28
Replace the loops by
a(1:1800)=50;
a(1801:3000)=90;
a(3001:3500)=0;
to match the figure
0 个评论
更多回答(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!