MATLAB C++ Math Library
  Go to function:
    Search    Help Desk 
colon    See Also

Generate a sequence of indices

C++ Prototype

Arguments

start
  Initial value

step
  Increment value

end
  Final value

C++ Syntax

MATLAB Syntax

Description

colon() generates a "sequence" of indices.  colon() stands for "every value." For example, A(colon()) means every value in array A.  A(1,colon()) means every column in the first row.

colon(start, end) generates a vector of (end - start) + 1 elements. The elements in the vector are start, start+1, start+2, , start+n, end. Each element in the vector is one greater than the preceding element. Iteration stops when the start+n is larger than end, yet the last value in the vector is always end. This can decrease the distance between the last two elements to less than 1.

colon(start, step, end) generates a vector of ((end - start)/step) + 1 elements. The elements in the vector are start, start+step, start+(2*step), start+(3*step), , start+(n*step), end. Iteration stops when the start+(n*step) is larger than end, yet the last value in the vector is always end. This can decrease the distance between the last two elements to less than step. Specifying a negative step generates a decreasing sequence. Specifying a sequence that will not terminate raises an exception.

See Also



[ Previous | Help Desk | Next ]