Sally
0
Q:

how to write a function in matlab

function ave = average(x)
    ave = sum(x(:))/numel(x); 
end
0
function f = fact(n)
    f = prod(1:n);
end
1
%%%% general syntax %%%%%%%%%%%%%
function [return parameters] = name_of_function(attributes)
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    body_of_the_function
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
end
2

New to Communities?

Join the community