Shinjin, your function is probably residing whithin a script, correct? If so, copy-paste the function into a new function window and save the file as average.m.
Alternatively, you could turn the script into a function and then call function average as shown here.