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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With