the coding between script file and function is the same, only the header is different
let's say I make in a script I want to calculate the mean of of some numbers
A= [ 1 2 3 4 5 6]
mean1= (1+2/2) mean2=(3+4/2) mean3=(5+6)/2
instead of writing and copying nearly the same code use a function that you create:( this just a simple example there is an inbuilt function for it of course) you start the function always with the header function .....
function [Mean]= CalcMean(Input)