Why I can't use the function of decimate

Hi, I try an example of decimation stated in matlab. But I don't get the result as shown in the example. What should I do? Below shows the result that I run in my matlab. The first image is from the examaple, the second image is the result that I get.
t = 0:1/4e3:1;
x = sin(2*pi*30*t) + sin(2*pi*60*t);
y = decimate(x,4);
subplot(2,1,1)
stem(0:120,x(1:121),'filled','MarkerSize',3)
grid on
xlabel('Sample Number')
ylabel('Original')
subplot(2,1,2)
stem(0:30,y(1:31),'filled','MarkerSize',3)
grid on
xlabel('Sample Number')
ylabel('Decimated')

 Accepted Answer

I get the same result as in the documentation (in R2020a).
First, what version of MATLAB are you using? The current online documentaion is for R2020a, however the decimate funciton could have changed over the years.
Second, run this line from a script or your Command Window:
which decimate -all
The only result should be:
C:\Program Files\MATLAB\R2020a\toolbox\signal\signal\decimate.m
or something similar for your version, if it is not R2020a.

5 Comments

In addition to these suggestions, I would create a new figure window, in case there is something lingering from prior axes, and also try on a freshly restarted MATLAB instance.
I am using R2020a version. But still, I don't get the result. It said that having an error
I have no idea what the problem could be with the stem call.
However, I notice that you have ‘decimate.m’ in your Current Folder. This could be the problem, since you may have written your own script or function and ‘overshadowed’ the MATLAB decimate funciton. I cannot determine this, because you have not yet answered my previous question.
I already delete the 'decimate.m' in my current folder. And it works! Thank you
As always, my pleasure!

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!