I have two vectors:
x = [3 6 7 10]y = [2 2 2 4]
I am trying to create vector
z = [3 3 6 6 7 7 10 10 10 10]
So each element x(i) is repeated y(i) times. This is straight forward with a for loop, but I'm trying to avoid looping, if possible. The size and values of x and y may change as well (they are populated by variables).
Here's the loop version:
z= []; for i = 1:numel(y) z= [z, repmat(x(i), 1, y(i))]; end
Any help is appreciated.
Best Answer