Set vector elements of one vector to nonzero elements of another
Mostrar comentarios más antiguos
So I have two vectors:
v1, v2, both same size.
I want to find all the elements where v2 is not zero and set the corresponding elements in v1 to those values, while leaving the other elements in v1 untouched.
E.g.
v1=[1 2 3 4 5] v2=[1 0 1 1 0]
Code I need goes here
v1 --> [1 2 1 1 5]
Can I do this without loops? Thanks.
1 comentario
Sean de Wolski
el 1 de Abr. de 2011
Another example of a well written question!
Respuesta aceptada
Más respuestas (1)
CP
el 1 de Abr. de 2011
0 votos
Categorías
Más información sobre Logical 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!