One problem you have is the decision that was made to make `[]` create the
unusable `Array{Nothing, 0}`. To create an array that you can actually fill
with values, you need to specify the type (eg. `Float64[]`)
I would just collect all the columns in a `Array{Float64,1}[]` array and
then call `hcat(x...)` on the result.
a_temp = Array{Float64,1}[]
b_temp = Array{Float64,1}[]
k = 1
while isfile("data$k.csv")
data = readcsv("data$k.csv")
push!(a_tmp, data[:,1])
push!(b_tmp, data[:,2])
k += 100 # thin the chain by 100
end
a = hcat(a_tmp...)
b = hcat(b_tmp...)
It would also work just as fine with `Any[]` (or `{}`) as the temporary
collection, but if you know the type, it I like write the type for
documentation.
Ivar
kl. 02:43:37 UTC+1 lørdag 1. mars 2014 skrev Ethan Anderes følgende:
>
> Hi Folks:
>
> Newbie here...
>
> I often need to write code that iteratively reads files which are saved
> from a long MCMC chain. Coming from Matlab I always try the following
>
>
> a = []
> b = []
> k = 1
> while isfile("data$k.csv")
> data = readcsv("data$k.csv")
> a = [a data[:,1]]
> b = [b data[:,2]]
> k += 100 # thin the chain by 100
> end
>
> This doesn't seem to work in julia. Does anyone have any recommendations
> on how to accomplish this in a nice julian way? Here is one example:
>
>
> a = Array(Float64,512,0)
> b = Array(Float64,512,0)
> k = 1
> while isfile("data$k.csv")
> data = readcsv("data$k.csv")
> a = [a data[:,1]]
> b = [b data[:,2]]
> k += 100
> end
>
> I would like to avoid this since it requires me to know I have 512 rows
> ahead of time. Of course, I could always do this
>
>
> data = readcsv("data1.csv")
> a = data[:,1]
> b = data[:,2]
> k = 101
> while isfile("data$k.csv")
> data = readcsv("data$k.csv")
> a = [a data[:,1]]
> b = [b data[:,2]]
> k += 100
> end
>
> ...but its not as clean.
>
>