Do I use the "for loop" correct or efficiently?

1 ビュー (過去 30 日間)
Bob
Bob 2021 年 8 月 28 日
編集済み: per isakson 2021 年 8 月 28 日
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

採用された回答

per isakson
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 件)

カテゴリ

Find more on Loops and Conditional Statements in Help Center and File Exchange

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by