I am master student in simulations in germany. I am newcomer from Matlab because the performance of Matlab is too low for my discretization in the additive manufactaring.
Julia is really nice, but I have a problem about the data container. I know structs and etc.
I used Structure Arrays in Matlab that was a easy way to manage the big data.
Please, watch the picture.
Its similar to structs but not the same in two points.
I can’t hand over single variabels to a struct and the initialization is not the know way.
For example:
struct Person
age::Int64
Marks::Vector{Float64}
end
x = Person(4,zeros(2,))
# x = Person(4) is not possible
#What I need is above
# First Person
Person[1].age = 4;
Person[1].Marks = zeros(2,);
# Second Person
Person[2].age = 5;
Person[2].Marks = ones(2,);
For performance reasons (if the solution above does not perform fast enough), you may want to use Immutable structs indeed, and in that case you need to “replace” the person in each position of your vector of persons.
julia> struct Person
age::Int64
Marks::Vector{Float64}
end
julia> persons = [Person(4,zeros(4)), Person(5,zeros(4))];
julia> persons[1] = Person(6,persons[1].Marks) # replace first person using the previous fields
julia> persons
2-element Vector{Person}:
Person(6, [0.0, 0.0, 0.0, 0.0])
Person(5, [0.0, 0.0, 0.0, 0.0])
Note that the elements of the Marks are mutable in both cases (being the Person struct mutable or not).
The trick here is that you are editing directly the component vector that holds the ages of all persons. (The structures themselves are generated on the fly when indexing into the StructArray.)