MATLAB: How to fix the error “Index exceeds matrix dimension

plotting

Hell, Im NEW to Matlab and I'm trying to plot the the stem function for the decimate sequence. I got the error msg saying "Index exceeds matrix dimension". Here is my code: The question is to use the the function decimate, using factor of 4 decimal and use the stem function to plot the original signal and the decimate. Use both default IRR and FIR decimate filter.
n1=0:100;
x1=cos(.15*pi.*n1);
d=decimate(x1,4);
subplot(2,1,1);
y1-stem(0:100,x(1:101), 'filled','markersize',3);
title('original signal');
subplot(2,1,2);
y11=stem(0:100,d(1:100), 'filled','markersize',3); % ERROR MSG SHOWS HERE.
title('decimate signal);
Could someone help to explain how I select the index/range for the "statment y11"? Appreciate much for your time and help. Thank you

Best Answer

You need to ‘decimate’ ‘n1’ to match the length and correct locations of ‘d’.
This works:
subplot(2,1,2);
n1d = 0:4:100; % ‘Decimate’ ‘n1’ To Match ‘d’
y11=stem(n1d, d, 'filled','markersize',3);
title('decimate signal');
EDIT Added plot.