Matlab plotting discrete time signals

AI Thread Summary
To graph the discrete time signal x[n] defined as 1 for 0≤n≤4 and 0 elsewhere in MATLAB, you can create a vector for n with desired limits and initialize a zero vector for x. Set the first five elements of x to 1 to represent the signal. The command "stem(n, x)" is recommended for plotting discrete data effectively. This method provides a clear visualization of the signal. The discussion highlights a straightforward approach to plotting discrete time signals in MATLAB.
Larrytsai
Messages
222
Reaction score
0
hey I was just wondering if anyone can teach me how to graph a signal like this


x[n] = { 1 for 0<=n<=4
{ 0 elsewhere

im not sure how to do this, what I have tried is

x = [1 1 1 1]

but this is not a function of 'n'.
 
Physics news on Phys.org
% You could do something like this:

n = [0:10]; % or whatever you want your limits to be
x = zeros(1,length(n));
x(1:5) = 1

stem(n, x); % fancy plotting for discrete data
 
Thank you so much this is exactly what I was looking for!
 

Similar threads

Replies
1
Views
2K
Replies
6
Views
5K
Replies
1
Views
2K
Replies
3
Views
1K
Replies
10
Views
2K
Replies
8
Views
2K
Replies
3
Views
1K
Back
Top