- Back to Home »
- MAT LAB »
- Function In Matlab
Posted by : Unknown
Tuesday, October 8, 2013
Function
Before defining function, i just tell you about the need of function. Why we use function in our code?Function makes our program easy and flexible. When we need to repeat some instruction in our program then we use a function.
Then the question is that if we just use function in our program to repeat our code then why we not use loop?
Difference between function and Loop
The answer is, loop execute at a time. It means if the compiler is in the loop then it remain there even the loop not terminate. While we can call function everywhere in our program , when we need.
Function in Matlab
·
Function Definition:
1.function addtwo(x,y)
x+y
end
2.function area =
traparea(a,b,h)
area = 0.5*(a+b)*h;
end
·
Function Call:
addtwo(5,4)
traparea(5,4,3)
For further information how function write in MATLAB,just visit my post.