Data Container like in Matlab Structure Arrays

Hello and welcome to the community!

If you want to change the fields of a struct after it has been created, it must be declared mutable, i.e.,

mutable struct Person
    age::Int64
    Marks::Vector{Float64}
end

you can also set default values for the fields like so:

Base.@kwdef mutable struct Person
    age::Int64 = 0
    Marks::Vector{Float64} = Float64[]
end

after this you can create a vector of persons

persons = [Person() for _ in 1:2]
persons[1].age  = 4;
persons[1].Marks = zeros(2,);
# Second Person
persons[2].age = 5;
persons[2].Marks = ones(2,);
1 Like