Hey,
In order to create a function in MATLAB, add a couple of lines to your code
function [out_1, out_2, ....., out_n] = function_name(in_1, in_2, ....., in_n)
….
<your script>
….
end
where,
out_k is your output variables from the function ( k = 1:n )
in_k is your input variables which you will pass into your function ( k = 1:n ), if you don't have any input parameters leave the parenthesis blank.
Note: function_name and filename should always be same, otherwise your code will throw an error.
For more details on functions in MATLAB and examples, please refer the following link, https://www.mathworks.com/help/matlab/ref/function.html
Hope this helps
Thanks,
Aakash Deep