| Author |
Comment/Response |
jf
|
10/27/12 1:02pm
abc needs to already have as many elements as you want to assign to.
In[1]:= abc = {0, 0, 0, 0, 0};
Do[abc[[i]] = i^2, {i, 1, 5}];
abc
Out[3]= {1, 4, 9, 16, 25}
The lazy way.
In[4]:= abc = Range[5]^2
Out[4]= {1, 4, 9, 16, 25}
Starting with an empty list and appending elements. General. Usually the slow way.
In[5]:= def = {};
Do[ AppendTo[def, i^2], {i, 1, 5}];
def
Out[7]= {1, 4, 9, 16, 25}
URL: , |
|