type T
x::Array{Float64,1}
f::Array{Float64,1}
T()=new(zeros(3),zeros(2))
end
v=Array{T}(10)
I would then like to write something like
x1[1:10]=v[1:10].x[1]
this doesn’t work because “type Array has no field x”. I can certainly extract all the x[1] from the individual members of the array v and put them in a vector x1 with a loop but I was wondering if there is a more Julia-esque way of doing it.
Interestingly, this is a good example of why the Array constructors have been changed in 0.7. In 0.7, to declare v the way you did you’d have to explicitly do
Well, not sure I would have voted for undef but uninitialized is definitely one of the hardest words to type in the English language, so I’m not complaining.
By the way, all of the suggestions here are good ones, but it’s worth noting that they’re all just helpful shortcuts for extracting each x element in a loop. One of the nicest things about Julia is that your first instinct (“extract all the x[1] from the individual members of the array v and put them in a vector x1 with a loop”) is basically the right thing to do and will be just as efficient as the “built-in” solutions like map. The map function is just nice because it creates that loop for you and makes the intent of your code clear.