Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a small problem that I cannot solve.

I have two tables, one with three elements:

a = {0, L/c, 2L/c};

and the other with 9 elements, all 0:

b = {0, 0, 0, 0, 0, 0, 0, 0, 0};

I would like to put the elements from table a into table b, giving so that I get the following table:

{0, L/c, 2L/c, 0, L/c, 2L/c, 0, L/c, 2L/c}

Can someone please give me some advice?

share|improve this question
Do you need b at all or do you simply want to generate a list of n repeated elements? – Yves Klett Jul 1 '13 at 7:03

I don't know if b is something important, but if it is not:

a = {0, L/c, 2 L/c}; 
PadLeft[a, 9, a]

{0, L/c, (2 L)/c, 0, L/c, (2 L)/c, 0, L/c, (2 L)/c}

and if it is:

b = ConstantArray[0, 9];
PadLeft[a, Length@b, a]

{0, L/c, (2 L)/c, 0, L/c, (2 L)/c, 0, L/c, (2 L)/c}

share|improve this answer
a = {0, L/c, 2 L/c};
b = ConstantArray[0, 9];
Flatten[ConstantArray[a, Length[b]/Length[a]]]

Or, even more succinctly:

  b = Flatten[ConstantArray[{0, L/c, 2 L/c}, 3]]
share|improve this answer
Just found out. Thank you very much bill – de_wight Jul 1 '13 at 7:04
@de_wight, if this answer has solved your problem, you should accept it by clicking on the check mark on the left. – m_goldberg Jul 1 '13 at 7:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.