define a function in matlab using @ code example
Example 1: declaring a function in matlab
%%%% general syntax %%%%%%%%%%%%%
function [return parameters] = name_of_function(attributes)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
body_of_the_function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
Example 2: matlab function
function ave = average(x)
ave = sum(x(:))/numel(x);
end
Example 3: how to write a function in matlab
function f = fact(n)
f = prod(1:n);
end