Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.0.0 - English


colon (:)

Ranging operator. Addresses all elements along an array dimension or of a list.

Description

Colon symbol : can be used to form implicit vectors (see also linspace, logspace) :

j:k

is the vector [j, j+1,...,k] (empty if j>k);

j:d:k

is the vector [j, j+d, ..., j+m*d].

The colon notation can also be used to pick out selected rows, columns and elements of vectors and other arrays (see also extraction, insertion):

A(:)

is the vector of all the elements of A regarded as a single column;

A(:,j)

is the j-th column of A;

A(i,:)

is the i-th row of A;

A(j:k)

is [A(j),A(j+1),...,A(k)];

A(:,j:k)

is

[A(1,j)  A(1,j+1)  ... A(1,k)
A(2,j)  A(2,j+1)  ... A(2,k)
. . . . . . . . . . .
A(M,j)  A(M,j+1)  ... A(M,k)]
if size of A is M-by-N;

A(j:k,:)

is

[A(j,1)    A(j,2)   ... A(j,N)
A(j+1,1)  A(j+1,2) ... A(j+1,N)
. . . . . . . . . . .
A(k,1)    A(k,2)   ... A(k,N)]
if size of A is M-by-N;

A(:)=w

fills the array A with entries of w (taken column by column if w is a 2D array). The amount of entries of A must be equal to the amount of entries of w.

Please note that even if i, j, k or d have a decimal part, only the integer part will be used.

type(:) is 129. typeof(:) is "implicitlist".

Examples

a = 1:5
b = 1:3:12
A = matrix(1:42,7,6);
// vector of all the elements of A
A(:)

// the j-th column of A
A(:,j)

// the i-th row of A
A(i,:)

// elements of columns from j to k and all rows
A(:,j:k)

// elements of all columns and rows from j to k
A(j:k,:)

w = matrix(101:142,7,6);
A(:) = w

// if indices are not integer
i = 1:0.4:10; //indices
A(i)

See also

  • dollar — ($) last index
  • extraction — matrix and list entry extraction
  • matrix — reshapes an array with the same number and order of components
  • linspace — generates linearly spaced numbers between 2 reached bounds
  • logspace — logarithmically spaced vector

History

VersionDescription
6.0
  • type(:) is 129 (as for 1:$) instead of 1. size(:) is undefined (instead of [-1,-1]).
  • typeof(:) is now "implicitlist", like 1:$.
  • %i:10 now yields an error.
Report an issue
<< brackets [,;] Scilab keywords comma >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 24 11:13:05 CEST 2024