フィルターのクリア

How do I change this system with function handles to linear equations to plot discretely?

2 ビュー (過去 30 日間)
Hi, I don't know how to implement a unit function and still plot discretely. Also, I don't really understand what the "double" does in my code but somehow I need it. Please advise - TIA.
u = @(n) double(n>=0); %converts symbolic u to array of n
uu = @(n) 1*(n>=0); %unit step function
x = @(n) u(n-2)-u(n-4);
n=[-2,12];
h = @(n) uu(n).*(sin(n).*exp(-n));
fplot(x,[-2,12]); %plots within x-limits
hold on
fplot(h,[-2,12]);
grid on
y = @(n) x(n).*h(n);
fplot(y,[-2,12]);

採用された回答

Walter Roberson
Walter Roberson 2024 年 2 月 4 日
移動済み: Walter Roberson 2024 年 2 月 4 日
u = @(n) double(n>=0); %converts symbolic u to array of n
uu = @(n) 1*(n>=0); %unit step function
x = @(n) u(n-2)-u(n-4);
n=[-2,12];
h = @(n) uu(n).*(sin(n).*exp(-n));
T = linspace(-2,12);
stem(T, x(T)); %plots within x-limits
hold on
stem(T, h(T));
grid on
y = @(n) x(n).*h(n);
stem(T, y(T));
ylim([-.1 1.1])
  2 件のコメント
balla243
balla243 2024 年 2 月 4 日
Thank you!
Can you please explain how "double" and plotting against a "linspace" makes this script work?
Walter Roberson
Walter Roberson 2024 年 2 月 4 日
The double() is not needed.
fplot() plots against the given range automatically, chosing plotting points according to how bumpy the function is. It does not plot discretely.
stem() plots discretely, but it needs to be told which points to plot.
u = @(n) (n>=0); %converts symbolic u to array of n
uu = @(n) 1*(n>=0); %unit step function
x = @(n) u(n-2)-u(n-4);
n=[-2,12];
h = @(n) uu(n).*(sin(n).*exp(-n));
T = linspace(-2,12);
stem(T, x(T)); %plots within x-limits
hold on
stem(T, h(T));
grid on
y = @(n) x(n).*h(n);
stem(T, y(T));
ylim([-.1 1.1])

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by