Julia: Modifying the same field in an array of Mutable Structs

Viewed 100

I am looking for the best way to adjust the same field, y, of an array of mutable structs, x to the same number.

x[:].y=0 kind of thing. In matlab I've seen it done using the deal() function. How can I do this in Julia?

2 Answers

You can use broadcasting:

setproperty!.(x, :y, 0)

Don't be afraid of writing the most obvious thing: a loop! It will be efficient in Julia. For example something like

for el in x
    el.y = 0
end
Related