matlab function in script code example Example: matlab function function ave = average(x) ave = sum(x(:))/numel(x); end