(1:s(1))
creates a vector of s(1)
elements starting from 1 and incrementing by 1 in each step. This is most commonly used in for
loops to iterate over the elements of a vector.
For example, if s(1) = 5
, then (1:s(1))
is equivalent to [1 2 3 4 5]
.
Here's an example of using it in a for
loop:
main.m154 chars6 lines
This will output:
main.m10 chars6 lines
Here, ii
iterates from 1 to 5 (inclusive) because s(1)
is set to 5.
gistlibby LogSnag