Functions are the m-files or MATLAB files that use input and output parameters to operate on some values given by user(inputs) and then display their results(outputs).
To declare/costruct functions open the editor/new script.
Wright the function definition/prototype in the first line,i.e
Function definition
è function[o1,o2,o3...]=function_name(i1,i2,i3...)
Where high lighted area is function definition, in which
Ä Function is the key word that is necessary to tell MATLAB that we are gonna declare/build a function.
Ä o1,o2,o3 and up-to so-on are representing output1,output2,output3 etc, you can use some other keywords in-place of o1,o2,o3 etc
Ä = is assignment operator.
Ä function_name is used to tell you people that it's the place where you can give a name to your function.
Ä i1,i2,i3 and up-to so-on are representing input1,input2,input3 etc
you can use some other keywords in-place of i1,i2,i3 etc
Ä Note that outputs should be enclosed in square brackets i.e [ ], and inputs should be enclosed in
parenthesis i.e ( )
? Then save your function note that while saving it you have to use the function_name as m-file name because they both should match in order to call it.
for example
|
function that calculates sum and diff. of two inputs. |
To download the above function click below.
0 comments:
Post a Comment