User defined axis for unit impulse sequence

6 ビュー (過去 30 日間)
Muhammad Sanwal
Muhammad Sanwal 2020 年 7 月 31 日
コメント済み: Muhammad Sanwal 2020 年 8 月 1 日
Hi,
I'm trying to solve a question that asks to create a function impseq (in function M-file), such that
function [x,n]=impseq(n0,n1,n2)
takes three parameters (n0, n1, n2) as input, where ‘n1’ and ‘n2’ are lower and upper limits of n-axis, and ‘n0’ is the delay, and generates a unit-impulse sequence using above mentioned three parameters. Finally, the question demands me to type “[x,n]=impseq(0,-5,5)” on the main window
So far, I've solved it as follows:
function [x,n] = impseq(n0,n1,n2)
n=-10:10;
x = @(n) (n == 0);
figure(2)
stem(n, x(n)), grid on
end
My question is that can i alter the n axis in a way such that it only plots the resulting graph upto its desired limits? Because even if I change the limits from n1= -5 to n2= 5, the n axis of the graph still ranges from -10 to 10.
  3 件のコメント
Alan Stevens
Alan Stevens 2020 年 8 月 1 日
Yes, you could do:
n = n1:n2;
or:
axis([n1 n2 0 1])
Muhammad Sanwal
Muhammad Sanwal 2020 年 8 月 1 日
It worked. Thankyou!

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

回答 (1 件)

Alan Stevens
Alan Stevens 2020 年 8 月 1 日
Just add:
axis([-5 5 0 1])
after the stem function line.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by