recreate vector

2 views (last 30 days)
Sam
Sam on 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

Accepted Answer

Sean de Wolski
Sean de Wolski on 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 Comment
Sam
Sam on 18 Jun 2012
Thanks Sean
Very helpful,
-Sam

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!