Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

b and d are two arrays that are given. I create aa and cc out of b andd`. This is what I do:

aa = {};
cc = {};

Do[If[j == 1, 
      AppendTo[aa, b[[i, j]]], 
      If[j == 2, AppendTo[cc, d[[i, j]]]]],
   {i, 1, 9, 1}, {j, 1, 2, 1}]

With this code I create the two vectors of length 9. The problem is that each time I execute the Do again, the length of my vectors increase by 9. How can keep their length fixed at 9?

share|improve this question
2  
Can't you do aa = b[[1;;9, 1]] and similar ? – b.gatessucks Mar 7 at 9:54
Yes!!!Thanks b.gatessucks!!:) – Mencia Mar 7 at 9:57
2  
Execute aa={};cc={}; (that is, reset aa and cc to empty set) before you execute Do[...]. But... why don't you use aa = b[[;;9, 1]];cc = d[[;;9, 2]]; instead? – kguler Mar 7 at 10:00

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.