Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
2  
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
add comment

2 Answers 2

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
add comment
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
1  
@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
add comment

Your Answer

 
discard

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.