Effacer les filtres
Effacer les filtres

recreate vector

1 vue (au cours des 30 derniers jours)
Sam
Sam le 18 Juin 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

Réponse acceptée

Sean de Wolski
Sean de Wolski le 18 Juin 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 commentaire
Sam
Sam le 18 Juin 2012
Thanks Sean
Very helpful,
-Sam

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by