Dear All,
Could you, please, give me a hand in a sorting problem:
mutable struct Vox
radiusR::Float64
x::Int32
y::Int32
z::Int32
end
Voxels=Vector{Vox}(undef, 0)
#loop starts here to fill the arrays of Vox structures
push!(Voxels,Vox(computeRadius[j,k,i], j, k, i))
#loop ends here
sort!(Voxels, by=expression, rev=true)
#e.g., expression=getfield.(tmp, :radiusR) or any other way to extract this vector of data
I get an error: ERROR: MethodError: objects of type Array{Float64,1} are not callable
Use square brackets for indexing an Array.
I tried many ways around with sort function, but finally only one worked as described below.
Now, if i substitute the above-mentioned array of structures with a tuple of the form:
v=Array{Tuple{Float64,Int,Int,Int}}(undef,0); loop to fill the array: push!(v,(computeRadius[j,k,i], j, k, i)); sort!(v, by=first, rev=true)
and i get what i want. Is there a way to sort original array of structures in a fast and elegant fashion?