1

I have that cell array:

Names={'L','A','C'}  

And I need to repeat cells to stay whit this:

Names2={'L','L','L','L','A','A','A','A','C','C','C','C'}

How can I do it in a easy way?

Thank you :)

  • What language/program do you use? – sancho.s ReinstateMonicaCellio Jul 28 '14 at 20:33
  • Matlab, sorry. Thanks – Lilia Jorge Jul 28 '14 at 20:36
  • @LiliaJorge please don't re-post an identical question if yours was already closed (i.e. http://stackoverflow.com/questions/24992087/repeat-cells-in-a-cell-array). The answer you got below was directly in the link I posted (and Natan has re-posted above) including more options. If you thought your question should have not been closed then you should comment on that question making your case. – Dan Jul 29 '14 at 08:07
  • 2
    and btw. please accept answers which solved your problem to indicate the system that the problem is solved. Thanks :) – Robert Seifert Jul 29 '14 at 08:47

1 Answers1

3
ind = kron([1,2,3],ones(1,4));
Names2 = Names(ind);

The above code uses kron. If you don't like it,

ind = repmat([1,2,3], 4, 1);
ind = reshape(ind, 1, []);
Yvon
  • 2,903
  • 1
  • 14
  • 36