MATLAB: How to plot the results of a conv

conv convulsion plot

I keep getting the error "Error using stem (line 41)X must be same length as Y.". I am trying to plot the results of a conv function. Here's what I have:
if true
% code
n = -10:1:10;
x1 = [0 0 0 0 0 0 0 0 1 2 1 1 2 1 2 1 2 0 0 0 0];
h1 = [0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0];
y1 = conv(x1,h1);
figure
stem(n,y1)
xlim([-10,10]);
ylim([-5,5]);
end
I know it's something with the range of the vectors resulting from the conv function The code runs correctly and will calculate the convulsion but the graph will not display and I get the error message.

Best Answer

Change your ‘y1’ assignment to:
y1 = conv(x1,h1,'same');
and it works.