Hi, newbie to Julia.
I am trying to run the following
> struct Bus
> bus_num::Int64
> bus_type::Int64
> bus_area::Int64
> bus_vmag::Float64
> bus_vangle::Float64
> bus_vnom::Float64
> bus_vmax::Float64
> bus_vmin::Float64
> end
>
> aBuses = Array{Bus}(undef,10)
> fields = ["Bus_N","Bus_Type","Area","V_Mag (pu)","V_Ang (deg)","V_Nom (kV)","Zone","V_max (pu)","V_min (pu)"];
> header = "Area";
> buses = aBuses[5,1]
> Dbus = 0
> # for i in 1:size(fields,1)
> idx = findall(x->x=="Area",fields)
> buses.bus_area = idx[1,1]
> # Dbus[:,i] = data[:,idx]
> # end
However, when I reach the last line
buses.bus_area = idx[1,1]
I received an error that
LoadError: setfield! immutable struct of type Bus cannot be changed
While reading the Julia manual, I understood that once an immutable struct has been defined, it is not possible to change its fields but it is still possible to change the value of a field. Apparently, it seems that this is not the case or I have not understood it right.
Since i am working on the modelling of an electrical network, my idea is to save the data of each bus, line, etc in a struct container (defined for each bus, line etc) and then store all these containers in one array i.e., Array_Bus = [bus_1_container, bus_2_container, and so on], where bus_1_container is the struct Bus that I have already defined in the code. However, I am unable to save the data for each individual field of the struct Bus due to the error that I have mentioned.
If I declare the struct Bus as mutuable, then entries of
aBuses = Array{Bus}(undef,10)
aBuses become undefined and I no longer can access them while executing the command
buses = aBuses[5,1]
Can someone shed some light what is the problem and how can I solve it?