I have the below R instance of Rs structure. I want to work on a specific field of all rows (as dealing with Matrix). So, I am using R[:].I[:] but it gives an error. Any way to do that?
Base.@kwdef mutable struct Rs
I::Vector{Float64} = [2,2,2]
Dot::Array{Float64, 2} = [0 0 0; 0 0 0; 0 0 0]
end
R = Rs[];
push!(R, Rs());
push!(R, Rs());
julia> R[:].I[:]
ERROR: type Array has no field I
Stacktrace:
[1] getproperty(x::Vector{Rs}, f::Symbol)
@ Base .\Base.jl:33
[2] top-level scope
@ REPL[1]:1
R is a vector, and doesn’t have a field, I. You can do R[i].I to access the field of the ith element of R. To get a vector of all the Is, you can try
getproperty.(R, :I)
R[:] doesn’t do anything useful, it just returns a vector of all the elements of R, so it’s equal to R itself.