for
The colon operator (or any array for that matter) can be used to generate index values for a loop.
Example: Create an array with each element a(i,j) initialized to i+j. We allocate the array first to avoid array index out-of-bounds errors.
a = zeros(25, 15);
for r = 1 : 25
for c = 1 : 15
a(r,c) = r + c;
end
end
Previous slide
Next slide
Back to first slide
View graphic version