1.funtion should be made in new m-file
2. u can make m-file by clicking the top left file ->New -> M File.
3. the format of first line (other than comments) should be
function [output1,output2] = file_name(input1,input2)
3. type " help function" in matlan cmd prompt to get more help.
4. MOST IMP::::: name of file should be same as name of funcution name
e.g function [output] = test (input1)
here the name of the file SHOULD BE test.m or it will never work.
5. U can have as many outputs and inputs u want in the fields named output1 and input1.
6. One u made the function u can execute it by wirtting the name of fucntion on the command prompt with inputs
e.g test(1)
where " 1 " is the input data...
Also if the function you are defining needs a second cutom function if may be defined within the same .m file as the main function.
It should be noted though that the second function will not be accessable from withing matlab and only the first function will be able to use it. (see example)
function [o1,o2] = function1(in1,in2) %Main definition in .m file
function [avg] = average(input_vector) %Sub function only available to function1