I would like to define a struct to hold a vector of 3 elements
mutable struct Coords
r::Array{Float64,3} # essentially holds x,y,z coords
end
I now want to make an array of these structures, and give random values to the vector inside each structure.
This is where I fade out. I have tried a few things which I will describe, but none of them worked.
trial 1:
x = 10 # I want the array to be of length 10
arrayOfStructs::Array{Coords,x}
for i=1:x
arrayOfStructs[i].r = rand(3)
end
The error message is
ERROR: LoadError: MethodError: Cannot `convert` an object of type Int64 to an object of type Array{C
oords,10}
Closest candidates are:
convert(::Type{T<:Array}, ::AbstractArray) where T<:Array at array.jl:489
convert(::Type{T<:AbstractArray}, ::T<:AbstractArray) where T<:AbstractArray at abstractarray.jl:1
4
convert(::Type{T<:AbstractArray}, ::LinearAlgebra.Factorization) where T<:AbstractArray at C:\User
s\julia\AppData\Local\Julia-1.0.2\share\julia\stdlib\v1.0\LinearAlgebra\src\factorization.jl:46
...
Stacktrace:
[1] setindex!(::Array{Array{Coords,10},1}, ::Int64, ::Int64) at .\array.jl:769
[2] getindex(::Type{Array{Coords,10}}, ::Int64) at .\array.jl:366
[3] top-level scope at C:\Users\Zarathustra\Documents\JuliaScripts\energyTest.jl:68 [inlined]
[4] top-level scope at .\none:0
in expression starting at C:\Users\Zarathustra\Documents\JuliaScripts\energyTest.jl:67
I don't get why it thinks there are integers involved.
I have tried changing the inside of the for loop to be
arrayOfStructs[i] = Coords(rand(3))
to no avail.
I have also tried initializing arrayOfStructs = []