You can create a loop in MATLAB using either the for
loop or the while
loop. Here are the basic syntax for both types of loops:
main.m37 chars4 lines
index
is the loop variable that takes the values specified in values
.statements
are the commands that will be executed in each iteration of the loop.Example:
main.m66 chars4 lines
main.m34 chars4 lines
condition
is the expression that determines whether the loop will continue executing or not.statements
are the commands that will be executed in each iteration of the loop.Example:
main.m89 chars6 lines
Once the loop has finished executing, MATLAB will continue with the commands immediately following the loop.
gistlibby LogSnag