Did you run the code in command window?
Matlab functions should be in m files, and as said above, the name of the function should be callable (i.e., the name of the file name should be same as the function.
FileName is my_function.m
content of the file:
then from command line you can call your my_function.