Matlab plotting discrete time signals

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 7K views
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!