- Scilab Help
- Elementary Functions
- Bitwise operations
- Complex numbers
- Discrete mathematics
- Matrix generation
- Log - exp - power
- Floating point
- Radix conversions
- Integers
- Matrix - shaping
- Matrix operations
- Search and sort
- Set operations
- Trigonometry
- &, &&
- extraction
- ind2sub
- insertion
- isempty
- isequal
- modulo
- ndims
- |, ||
- size
- sub2ind
Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
extraction
matrix and list entry extraction
Syntax
x(i) x(i,j) x(i,j,k,..) [...] = l(i) [...] = l(k1)...(kn)(i) or [...] = l(list(k1,...,kn,i)) l(k1)...(kn)(i,j) or l(list(k1,...,kn,list(i,j))
Arguments
- x
matrix of any possible types
- l
list variable
- i,j, k
indices
- k1,...kn
indices
Description
Matrix case
i
, j
,
k
,.. can be:
- a real scalar or a vector or a matrix with positive elements.
r=x(i,j)
builds the matrixr
such asr(l,k)=x(int(i(l)),int(j(k)))
forl
from 1 tosize(i,'*')
andk
from 1 tosize(j,'*')
.i
(j
) Maximum value must be less or equal tosize(x,1)
(size(x,2)
).r=x(i)
withx
a 1x1 matrix builds the matrixr
such asr(l,k)=x(int(i(l)),int(i(k)))
forl
from 1 tosize(i,1)
andk
from 1 tosize(i,2)
.Note that in this case index
i
is valid only if all its entries are equal to one.r=x(i)
withx
a row vector builds the row vectorr
such asr(l)=x(int(i(l)))
forl
from 1 tosize(i,'*')
i
Maximum value must be less or equal tosize(x,'*')
.r=x(i)
withx
a matrix with one or more columns builds the column vectorr
such asr(l)
(l
from 1 tosize(i,'*')
) contains theint(i(l))
entry of the column vector formed by the concatenation of thex
's columns.i
Maximum value must be less or equal tosize(x,'*')
.
- the symbol
:
which stands for "all elements".
r=x(i,:)
builds the matrixr
such asr(l,k)=x(int(i(l)),k))
forl
from 1 tosize(i,'*')
andk
from 1 tosize(x,2)
r=x(:,j)
builds the matrixr
such asr(l,k)=x(l,int(j(k)))
forl
from 1 tosize(r,1)
andk
from 1 tosize(j,'*')
.r=x(:)
builds the column vectorr
formed by the column concatenations ofx
columns. It is equivalent tomatrix(x,size(x,'*'),1)
.
- a vector of boolean
If an index (
i
orj
) is a vector of booleans it is interpreted asfind(i)
or respectivelyfind(j)
- a polynomial
If an index (
i
orj
) is a vector of polynomials or implicit polynomial vector it is interpreted ashorner(i,m)
or respectivelyhorner(j,n)
wherem
andn
are associatedx
dimensions. Even if this feature works for all polynomials, it is recommended to use polynomials in$
for readability.
For matrices with more than 2 dimensions (see:hypermatrices) the dimensionality is automatically reduced when right-most dimensions are equal to 1.
List or Tlist case
If they are present the ki
give the path to
a sub-list entry of l
data structure. They allow
a recursive extraction without intermediate copies. The
instructions
[...]=l(k1)...(kn)(i)
and
[...]=l(list(k1,...,kn,i))
are interpreted as:
lk1 = l(k1)
.. = ..
lkn = lkn-1(kn)
[...] = lkn(i)
.
And the l(k1)...(kn)(i,j)
and
l(list(k1,...,kn,list(i,j))
instructions
are interpreted as:
lk1 = l(k1)
.. = ..
lkn = lkn-1(kn)
lkn(i,j)
When path points to more than one list component, the instruction must have as many left-hand side arguments as selected components. But if the extraction syntax is used as function parameters, each returned list component is added to the function parameters.
Note that l(list())
is the same as
l
.
- i and j may be:
- real scalar or vector or matrix with positive elements.
[r1,...rn]=l(i)
extracts thei(k)
elements from the listl
and store them inrk
variables fork
from 1 tosize(i,'*')
- the symbol
:
which stands for "all elements".
- a vector of booleans.
If
i
is a vector of booleans it is interpreted asfind(i)
.- a polynomial
If
i
is a vector of polynomials or implicit polynomial vector it is interpreted ashorner(i,m)
wherem=size(l)
. Even if this feature works for all polynomials, it is recommended to use polynomials in$
for readability.
- k1 ... kn may be :
- real positive scalar
- a polynomial
interpreted as
horner(ki,m)
wherem
is the corresponding sub-list size.- a character string
associated with a sub-list entry name.
Remarks
For soft coded matrix types such as rational functions and state
space linear systems, x(i)
syntax may not be used for
vector element extraction due to confusion with list element extraction.
x(1,j)
or x(i,1)
syntax must be
used.
Examples
Matrix case:
a = [1 2 3 ; 4 5 6] a(1,2) a([1 1], 2) a(:, 1) a(:, 3:-1:1) a(1) a(6) a(:) a([%t %f %f %t]) a([%t %f], [2 3]) a(1:2, $-1) a($:-1:1, 2) a($) // x = 'test' x([1 1 ; 1 1 ; 1 1]) // b = [1/%s, (%s+1)/(%s-1)] b(1,1) b(1,$) b(2) // the numerator
List ot Tlist case:
See also
- insertion — partial variable assignation or modification
- colon — Ranging operator. Addresses all elements along an array dimension or of a list.
- find — gives the indices of %T or non-zero elements
- horner — evaluates some polynomials or rationals for given values
- parentheses — ( ) left and right parenthesis
Report an issue | ||
<< &, && | Elementary Functions | ind2sub >> |