MATLAB: Hi. So I keep getting an error that the vectors must be of equal length in the last plot. Where it says plot(t,c) Someone pleaseeee help me with this. How to solve it

clear all
clc
t=0:0.001:5;% with a step of 0.001
y=heaviside(t);%function for unit step
subplot(5,1,1);
plot(t,y);%plotting unit step
title('Unit step function');
y1=heaviside (t-1);%for shifted unit step
subplot(5,1,2);
plot(t,y1);%plotting the shifted unit step
title('Shifted unit step function');
x=y-y1;
subplot(5,1,3);
plot(t,x);%plotting x(t)
title('graph for x(t)');
h=10*exp(-10*t);
subplot(5,1,4);
plot(t,h);
title('exponetial function');
c=conv(x,h);
subplot(5,1,5);
plot(t,c);
title('convoled signal');

Best Answer

Add the 'same' shape argument to your conv call and it works:
t=0:0.001:5;% with a step of 0.001
y=heaviside(t);%function for unit step
subplot(5,1,1);
plot(t,y);%plotting unit step
title('Unit step function');
y1=heaviside (t-1);%for shifted unit step
subplot(5,1,2);
plot(t,y1);%plotting the shifted unit step
title('Shifted unit step function');
x=y-y1;
subplot(5,1,3);
plot(t,x);%plotting x(t)
title('graph for x(t)');
h=10*exp(-10*t);
subplot(5,1,4);
plot(t,h);
title('exponetial function');
c=conv(x,h,'same');
subplot(5,1,5);
plot(t,c);
title('convoled signal');