Hi @lara, welcome!
Do I need to put this operations inside a function or I can do just like the example below?
A great read, if you haven’t already, is Performance Tips · The Julia Language.
The first two points are:
Since this setup code isn’t performance sensitive, if it works, then you can leave it as the example.
In general though, you’ll benefit from creating a function because it’s a better software engineering practice. You can test that it returns the right outputs for a given input, you can move it somewhere else as a single blob, and it removes the dependence global variables.