It'd probably be fastest if you can pre-allocate your array:

A = Array(ASCIIString, 3, 2)
for i=1:size(A, 1)
    A[i, 1] = string('w'+i, 1)
    A[i, 2] = string('w'+i, 2)
end

If you don't know how many elements you'll have, you can use two column 
vectors, `c1` and `c2`, and push to them independently.  Then horizontally 
concatenate them together to get your resulting `A = [c1 c2]`.

On Tuesday, April 12, 2016 at 10:38:41 AM UTC-4, Fred wrote:
>
> Thank you very much Tim !
>
> In fact I want to create an X,Y array so if I create a 1D array, I can 
> only append to it (x1,y1) then (x2,y2)... (xn, yn), because I calculate x1 
> before x2...
>
> julia> d = ["x1", "y1", "x2", "y2", "x3", "y3"]
> 6-element Array{ASCIIString,1}:
>  "x1"
>  "y1"
>  "x2"
>  "y2"
>  "x3"
>  "y3"
>
> julia> reshape(d,3,2)
> 3x2 Array{ASCIIString,2}:
>  "x1"  "y2"
>  "y1"  "x3"
>  "x2"  "y3"
>
> you see the problem ? instead I would like to have :
> x1 y1
> x2 y2
> ..
> xn yn 
>
> because I want to be able to work on columns and line ... of course 
> another easy solution is to use dataframes, but I tried with arrays because 
> the code should be faster... :)
>
> Le mardi 12 avril 2016 16:27:50 UTC+2, Tim Holy a écrit :
>>
>> Note that in `a = Array{Float64,2}`, `a` is a *type*, not an *instance*. 
>> You 
>> presumably mean `a = Array(Float64, 0, 0)`. 
>>
>> But Yichao is right that you can't grow a 2d array, only a 1d one. 
>>
>> Best, 
>> --Tim 
>>
>

Reply via email to