Make Function Equal Zero After Certain Time

12 ビュー (過去 30 日間)
s.v.
s.v. 2018 年 4 月 4 日
コメント済み: Star Strider 2018 年 4 月 4 日
Hi all, I am in need of some help. I am trying to use if and else statements to plot the following function. Here is my current code:
HP = 60/72;
Tas = 0.105;
Elamin = 0.12;
Elamax = 0.28;
Eramin = 0.05;
Eramax = 0.15;
t = [0:0.001:HP];
if t > Tas
aa = 0;
else
aa = sin((pi*t)/Tas);
end
ela = Elamin + (Elamax - Elamin)*aa;
era = Eramin + (Eramax - Eramin)*aa;
plot(t,ela, t,era, t,aa);
Basically, I am trying to say that for 0<t<Tas, the function aa is calculated. Otherwise, the function aa = 0. Attached is the current plot I am getting if I do not include the if/else statements. Its kind of what I want, except the graph must level to around y = 0 after x = Tas (about 0.105s).
Any help is appreciated!

採用された回答

Star Strider
Star Strider 2018 年 4 月 4 日
Try this:
aa = @(t, Tas) sin((pi*t)/Tas) .* ((0 <= t) & (t <= Tas)); % Function, With Conditions As A Logcal Index Vector
t = linspace(-1, 1, 150); % Time Vector
Tas = 0.105;
figure
plot(t, aa(t, Tas))
grid
  6 件のコメント
s.v.
s.v. 2018 年 4 月 4 日
Thank you.
Star Strider
Star Strider 2018 年 4 月 4 日
As always, my pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by