フィルターのクリア

Matlab AND operation concerning intervals

1 回表示 (過去 30 日間)
Aaron Friedman
Aaron Friedman 2016 年 4 月 2 日
コメント済み: Aaron Friedman 2016 年 4 月 3 日
I am trying to create a simple signal with the following code:
function s = r_tri(t)
if ((t >= 0) & (t <= 3))
s = (-2/3)*t + 2;
else
s = 0;
end
Every time I try and plot this I get a blank graph. I assigned t = -1: 0.01: 4; I used the following plot command:
plot (t, r_tri(t))
I also tried this on the command line, and I keep getting 0. Why is this happening? Can you suggest a better way to accomplish this? Thanks.

採用された回答

Walter Roberson
Walter Roberson 2016 年 4 月 2 日
function s = r_tri(t)
s = zeros(size(t));
mask = (t >= 0) & (t <= 3);
s(mask) = (-2/3)*t(mask) + 2;
  1 件のコメント
Aaron Friedman
Aaron Friedman 2016 年 4 月 3 日
Thank you.

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 2 日
t = -1: 0.01: 4;
s=zeros(size(t))
idx=t>=0 & t<=3;
s(idx)=(-2/3)*t(idx) + 2;
plot(t,s)
  1 件のコメント
Aaron Friedman
Aaron Friedman 2016 年 4 月 3 日
Thanks!

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by