Do I use the "for loop" correct or efficiently?
조회 수: 1 (최근 30일)
이전 댓글 표시
Is there a better way or more efficient?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/723579/image.png)
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!