- Back to Home »
- MAT LAB »
- Loops In matlab
Posted by : Unknown
Tuesday, October 8, 2013
·
While Loops
While statements repeatedly execute a piece of code
while given condition is true. The syntax of while statement is:
while condition
do
something
end
·
For Loops
For statements repetitively execute piece of code
given number of times. The syntax of for statement is:
for counter =
start:step:stop
do
something
end
Example:
Implement the factorial using functions and loop
Creating M-File In MATLAB
functions fact= factorial(num)
for i=num : -1 : 1
fact= fact*i
end;
end
I hope this is helpful for you...
Creating M-File In MATLAB
functions fact= factorial(num)
for i=num : -1 : 1
fact= fact*i
end;
end
I hope this is helpful for you...