From: Will on
Hi,

Just a quick question:

Does anyone know whether it is faster to pass a variable to a function as an argument or to import global variables within the function body?
From: Cokelid on
On Feb 16, 7:24 am, "Will " <w.brad...(a)bradford.ac.uk> wrote:

> Does anyone know whether it is faster to pass a variable to a function as an argument or to import global variables within the function body?

The difference should be negligible, but I would definitely favour
passing as an argument as better programming practice.

If you subsequently modify the passed-in variable then Matlab will
make a copy of the variable local to that function (with the
associated overhead), however if it's read-only then it will
effectively remain as passed-by-reference and there should be
practically no difference.
From: Will on
Thanks for the response. At the moment the global variables I use are just look-up tables so they are not modified. But I will bear in mind what you have said.

Cheers.