フィルターのクリア

How to plot a Step function?

5 ビュー (過去 30 日間)
Juan Rosado
Juan Rosado 2012 年 12 月 4 日
I am trying to generate a code to plot a step function that depends on t.
I am proceding the following way, but I get an error every time I run it,
clc,clear
t = [-100 : 100]';
tt = [t - 1];
for ii = 1 : 201
if t(ii) >= 0
t(ii) = 1;
else
t(ii) = 0;
end
end
for i = 1 : 201
if tt(i) >= 0
tt(i) = 1;
else
tt(i) = 0;
end
end
t1 = [-100 : 100];
y = t1 .* (t - tt);
plot(y,t1)
What I want is that for the input t, when t is >= 0 the value of the function is 1, and for everything else 0 and then plot the results.

採用された回答

Walter Roberson
Walter Roberson 2012 年 12 月 4 日
stairs(t, t >= 0)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolar Power についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by