Error using stem()...... X must be same length as Y.
23 views (last 30 days)
Show older comments
clc;
clear all;
close all;
i=-5:0.1:5;
l=length(i);
%unit step signal
for t=1:1
if i(t)<0
u(t)=0;
else
u(t)=1;
end;
end;
figure(1)
subplot(2,1,1);
plot(i,u);
xlabel('time');
ylabel('amplitude');
title('continous time unit step');
subplot(2,1,2);
stem(i,u);
xlabel('time');
ylabel('amplitude');
title('discrete time unit step');
Accepted Answer
More Answers (1)
KSSV
on 20 Sep 2023
I have given one wproper working code for unit step signal. Understand it and change the others like wise.
t=-5:0.1:5;
nt = length(t) ;
%unit step signal
u = zeros(1,nt) ;
for i=1:nt
if t(i) < 0
u(i)=0;
else
u(i)=1;
end
end
figure(1)
subplot(2,1,1);
plot(t,u);
xlabel('time');
ylabel('amplitude');
title('continous time unit step');
subplot(2,1,2);
stem(t,u);
xlabel('time');
ylabel('amplitude');
title('discrete time unit step');
You need not to use aloop. Without loop:
t=-5:0.1:5;
nt = length(t) ;
%unit step signal
u = ones(1,nt) ;
u(t<0) = 0 ;
figure(1)
subplot(2,1,1);
plot(t,u);
xlabel('time');
ylabel('amplitude');
title('continous time unit step');
subplot(2,1,2);
stem(t,u);
xlabel('time');
ylabel('amplitude');
title('discrete time unit step');
0 Comments
See Also
Categories
Find more on Detection in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!