how to create function handle for conditional sine wave

1 次查看(过去 30 天)
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 个评论
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
fun = @(t) sin(3*pi*n) .* (n>=0 & n<=5);

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by