Filter löschen
Filter löschen

recreate vector

1 Ansicht (letzte 30 Tage)
Sam
Sam am 18 Jun. 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

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 18 Jun. 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 Kommentar
Sam
Sam am 18 Jun. 2012
Thanks Sean
Very helpful,
-Sam

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by