help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: colon operation


From: Richard Kirk
Subject: Re: colon operation
Date: Sat, 28 Mar 2020 20:14:06 +0000

In addition to the other replies…

The colon is used a bit like an ellipsis. You might write 0,1,2,3,4,5,6,7,8,9 as 0..9, or 0 to 9. The colon is two dots but one on top of another, but it means the same thing: you can write this as 1:9. So if you type [0:9] you get…

ans =

   0   1   2   3   4   5   6   7   8   9


If you are using this as an index for an array, then the legal values have a fixed range. In your case, you could have written…

a (1:2,1:6, 3,10,6,1)

..and got the same result. However, we know the range of possible numbers to use in the index. The lowest index is always 1, so we can omit the start values when we are using an index…

a (:2,:6, 3,10,6,1)

The highest index is stet by the size of the array in that dimension, so we can omit that too if we want all the values…

a (:,:, 3,10,6,1)

I guessed the dimensions because of the format of the output. Type ones(2,6) and you get…

ans =

   1   1   1   1   1   1
   1   1   1   1   1   1

Hope this helps.

Richard Kirk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]