find the average of a vector with specific condition ?
Mostrar comentarios más antiguos
I had A vector
A=[1 0 0 2 3 2 3 5 0 0 0 0 1 2 1 0 0 0 0 3 4 0 0 0 0 0 0 1 2 3 2 0 0 0 0 2 0 0]
like this. Now I want a vector B having average of corresponding non-zero value, like
B(1)=average(A(1));
B(4)=average(A(4):A(8));
B(13)=average(A(13):A(15);
B(20)=average(A(20):A(21));
B(28)=average(A(28):A(31)) and so on .....rest values should be zeros.
hence
B=[1 0 0 3 0 0 0 0 0 0 0 0 1.33 0 0 0 0 0 0 3.5 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 ]
5 comentarios
jonas
el 4 de Sept. de 2018
I've seen a number of your similar questions. Just out of curiosity, can I ask what the application is?
MUKESH KUMAR
el 4 de Sept. de 2018
jonas
el 4 de Sept. de 2018
Right, I figured that much :)
MUKESH KUMAR
el 4 de Sept. de 2018
jonas
el 4 de Sept. de 2018
I'll give it a try in an hour if no one gave you an answer. This one is not as straight-forward as your previous questions, at least to me.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!