Borrar filtros
Borrar filtros

recreate vector

1 visualización (últimos 30 días)
Sam
Sam el 18 de Jun. de 2012
I have a compressed vector like this: a_compressed = [9 3 5] a_ending_indx = [4 6 9]
Without using FOR loop, what is the efficient way to uncompress that vector so that the full vector is a = [9 9 9 9 3 3 5 5 5]
Thanks, Sam

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 18 de Jun. de 2012
One of many ways:
a_c = [9 3 5];
a_x = [4 6 9];
B = zeros(1,a_x(end));
B([1 a_x(1:end-1)+1]) = 1;
C = a_c(cumsum(B))
  1 comentario
Sam
Sam el 18 de Jun. de 2012
Thanks Sean
Very helpful,
-Sam

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by