0

I have already learning to use downsample() function inside Matlab. However, I am wondering if it can be implemented using basic for loop or if statement. Can anyone help me? P.S Below is the code I have worked out, I would like to know if there is a different way to do it.

for i=1:M:length(x)
y=[y x(i)];
end
end

`

WilliamW
  • 17
  • 6

1 Answers1

2

If M is a scalar integer value, and x is a vector, then x(1:M:end) takes every Mth element.

x = 1:14;
M = 4;
x(1:M:end)
ans =

     1     5     9    13

You can start at a different value too: x(3:M:end).

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120