extract some special element from a vector and reverse it?

I have a vector like this:
s=[5 9 0 6 0 7 8 3 0 4 1 2]
i extracted a subvector from this vector witch does not have zero:
SubVector=[6 7 8 3 4]
and i want to reverse this vector in s to have SP like this:
SP=[5 9 0 4 0 3 8 7 0 6 1 2]
how can i do this with a fast and clean code?

2 comentarios

dpb
dpb el 17 de Nov. de 2013
'Pends on how the subvector selection is/was specified???
zeros must be fix, just nonzeros must be revesd.

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 17 de Nov. de 2013
Editada: Azzi Abdelmalek el 17 de Nov. de 2013
s=[5 9 0 6 0 7 8 3 0 4 1 2];
SubVector=[6 7 8 3 4];
[ii,jj]=ismember(SubVector,s);
s(jj)=fliplr(SubVector)

Más respuestas (0)

Categorías

Preguntada:

el 17 de Nov. de 2013

Comentada:

el 17 de Nov. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by