how to create function handle for conditional sine wave

I want to create function handle that satisfies the following discrete sinusoid
n = -10:1:10;
x = sin(3*pi*n);
x(n<0) = 0 ;
x(n>5) = 0 ;
stem(n,x)

3 件のコメント

Stephen23
Stephen23 2018 年 8 月 31 日
編集済み: Stephen23 2018 年 8 月 31 日
@Romio: what have you tried so far? What problems are you having?
Romio
Romio 2018 年 8 月 31 日
my go was
x = @(t) sin(3*pi*n)
However, I was not able to include the given conditions, i.e. x(n<0) = 0 and x(n>5) = 0 in the fuction handle
Stephen23
Stephen23 2018 年 8 月 31 日
編集済み: Stephen23 2018 年 8 月 31 日
@Romio: in your question you use x for a numeric vector, but in your comment you use x for a function handle. This is confusing.

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

回答 (1 件)

Stephen23
Stephen23 2018 年 8 月 31 日
編集済み: Stephen23 2018 年 8 月 31 日

0 投票

fun = @(t) sin(3*pi*n) .* (n>=0 & n<=5);

カテゴリ

ヘルプ センター および File ExchangeCall C++ from MATLAB についてさらに検索

質問済み:

2018 年 8 月 31 日

編集済み:

2018 年 8 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by