How to downsample a vector x by an integer factor M with a single statement such as for loop or conditional statements

 Respuesta aceptada

a = 1:10;
b = downsample(a, 3) % use downsample
b = 1×4
1 4 7 10
c = a(1:3:end) % statement
c = 1×4
1 4 7 10

3 comentarios

Thank you for your answer! Could you please offer a solution with for loop or if statement?
"for loop" is not as efficient as above. You should not use it.
a = 1:10;
j=1;
for i=1:3:length(a)
b(j) = a(i);
j = j+1;
end
b
b = 1×4
1 4 7 10

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2021a

Preguntada:

el 16 de Sept. de 2021

Comentada:

el 16 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by