Professional Documents
Culture Documents
Notes On MATLAB Functions
Notes On MATLAB Functions
Notes On MATLAB Functions
edu
function[W]= myfun(x,y,z])
OR equivalently
function[ ]= ellipse(L,S,theta)
OR equivalently
Function = ellipse(L,S,theta)
This could be for a function that draws an ellipse with major & minor axes L and S and rotation theta 2.
Function Call
General: we have to give values for the inputs and use variable name that store the values of the outputs. Below are examples of how the above functions are called a.
[A,B,C] = yourfun(-5,4)
This means that input values are x=-5, y=4, and output values for A, B, and C, are calculated according to the function prescription
b.
[M] = myfun(2,4,-3)
OR equivalently
M = myfun(2,4,-3)
c.
ellipse(10,5,pi/6)
[a,b,c] = feval(yourfun,-4,5)
or alternatively we can define a function handle for yourfun, call it func1 and use it with feval:
Distance=inline(sqrt(Ra.^2+Rb.^2... -2*Ra.*Rb.*cos(ab)),Ra,Rb,ab)
Note that because the statement was too long we used ... for continuation. In the command file the following will appear: