How can I fix the error "Index exceeds matrix dimension

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

1 Comment

i didn't get the answer. got error in the following line
imshow(xTrainImages{i});

Sign in to comment.

 Accepted 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.

4 Comments

Dear Star Strider, Thank you so much for your inputs. I have another question, hope you could help. How do you get 26 elements. Thanks again.
The 26 elements in each of ‘d’ and ‘n1d’ is the result of ‘decimating’ (here, taking every 4th element) of both vectors.
I probably should have created ‘n1d’ as:
n1d = n1(1:4:end);
that would have made it more obvious. The result is the same.
Got it, thank you so much!

Sign in to comment.

More Answers (2)

The reason for the error message is undoubtedly the fact that d has only 26 elements, not one hundred, so d(1:100) is invalid.
am generating overlap save method signals in matlab am getting an error "index exceeds"as shown in picture please help me to solve this

Tags

Asked:

Jo
on 10 Feb 2017

Commented:

on 3 May 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!