How do I create a vector of the average of consecutive elements of another vector (without using a loop)?
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Rinu
el 10 de Oct. de 2013
Comentada: Sk Rafidul
el 11 de Mayo de 2019
Say, I have a vector A=[2 4 6 8 10]. Is there any way I can create a vector of the average of consecutive elements of A, i.e. B=[3 5 7 9] without using a loop? Is there any matlab function to do that? Thanks in advance.
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 10 de Oct. de 2013
Editada: Azzi Abdelmalek
el 10 de Oct. de 2013
A=[2 4 6 8 10]
B=mean([A(1:end-1);A(2:end)])
2 comentarios
Más respuestas (2)
Matthew Crema
el 10 de Oct. de 2013
One way:
A=[2 4 6 8 10];
foo = conv([1 1], A)/2;
B = foo(2:end-1)
B =
3 5 7 9
-Matt
5 comentarios
Andrei Bobrov
el 11 de Oct. de 2013
Editada: Andrei Bobrov
el 11 de Oct. de 2013
conv2(A,[.5 .5],'valid')
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!