insertion
partial variable assignation or modification
assignation
partial variable assignation
Syntax
x(i,j)=a x(i)=a l(i)=a l(k1)...(kn)(i)=a or l(list(k1,...,kn,i))=a l(k1)...(kn)(i,j)=a or l(list(k1,...,kn,list(i,j))=a
Arguments
- x
matrix of any kind (constant, sparse, polynomial,...)
- l
list
- i,j
indices
- k1,...kn
indices with integer value
- a
new entry value
Description
Matrix case
If x is a matrix the indices i and j, may be:
- Real scalars or vectors or matrices
In this case the values given as indices should be positive and only their integer part are taken into account.
If
ais a matrix with dimensions(size(i,'*'),size(j,'*')),x(i,j)=areturns a newxmatrix such asx(int(i(l)),int(j(k)))=a(l,k)forlfrom 1 tosize(i,'*')andkfrom 1 tosize(j,'*'), other initial entries ofxare unchanged.If
ais a scalarx(i,j)=areturns a newxmatrix such asx(int(i(l)),int(j(k)))=aforlfrom 1 tosize(i,'*')andkfrom 1 tosize(j,'*'), other initial entries ofxare unchanged.If
iorjmaximum value exceed correspondingxmatrix dimension, arrayxis previously extended to the required dimensions with zeros entries for standard matrices, 0 length character string for string matrices and false values for boolean matrices.x(i,j)=[]kills rows specified byiifjmatches all columns ofxor kills columns specified byjifimatches all rows ofx. In other casesx(i,j)=[]produce an error.x(i)=awith anavector returns a newxmatrix such asx(int(i(l)))=a(l)forlfrom 1 tosize(i,'*'), other initial entries ofxare unchanged.x(i)=awith anascalar returns a newxmatrix such asx(int(i(l)))=aforlfrom 1 tosize(i,'*'), other initial entries ofxare unchanged.If
imaximum value exceedsize(x,1),xis previously extended to the required dimension with zeros entries for standard matrices, 0 length character string for string matrices and false values for boolean matrices.- if
xis a 1x1matrix
amay be a row (respectively a column) vector with dimensionsize(i,'*'). Resultingxmatrix is a row (respectively a column) vector- if
xis a rowvector
amust be a row vector with dimensionsize(i,'*')- if
xis a columnvector
amust be a column vector with dimensionsize(i,'*')- if
xis a generalmatrix
amust be a row or column vector with dimensionsize(i,'*')andimaximum value cannot exceedsize(x,'*').
x(i)=[]kills entries specified byi.
- The : symbol
The
:symbol stands for "all elements".x(i,:)=ais interpreted asx(i,1:size(x,2))=ax(:,j)=ais interpreted asx(1:size(x,1),j)=ax(:)=areturns inxtheamatrix reshaped according toxdimensions.size(x,'*')must be equal tosize(a,'*').
- Vectors of boolean
If an index (
iorj) is a vector of booleans it is interpreted asfind(i)or respectivelyfind(j).- Polynomials
If an index (
iorj) is a vector of polynomials or implicit polynomial vector it is interpreted ashorner(i,m)or respectivelyhorner(j,n)wheremandnare associatedxdimensions. Even if this feature works for all polynomials, it is recommended to use polynomials in$for readability.
List or Tlist case
If they are present the
kigive the path to a sub-list entry ofldata structure. They allow a recursive insertion without intermediate copies. Thel(k1)...(kn)(i)=aandl(list(k1,...,kn,i)=a)instructions are interpreted as:lk1 = l(k1).. = ..lkn = lkn-1(kn)lkn(i) = alkn-1(kn) = lkn.. = ..l(k1) = lk1And the
l(k1)...(kn)(i,j)=aandl(list(k1,...,kn,list(i,j))=ainstructions are interpreted as:lk1 = l(k1).. = ..lkn = lkn-1(kn)lkn(i,j) = alkn-1(kn) = lkn.. = ..l(k1)= lk1imay be :a real non negative scalar (only its integer part is taken into account).
l(0)=aadds an entry on the "left" of the list.l(i)=asets theientry of the listltoa. Ifi>size(l),lis previously extended with zero length entries (undefined).l(i)=null()deletes theith list entry.a polynomial. If
iis a polynomial 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,..knmay be :real positive scalar.
a polynomial, interpreted as
horner(ki,m)wheremis 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 must not be used for vector entry
insertion due to confusion with list entry insertion. x(1,j)
or x(i,1) syntax must be used.
Examples
Matrix cases:
a = [1 2 3;4 5 6] a(1,2) = 10 a([1 1],2) = [-1;-2] a(:,1) = [8;5] a(1,3:-1:1) = [77 44 99] a(1) = %s a(6) = %s+1 a(:) = 1:6 a([%t %f],1) = 33 a(1:2,$-1) = [2;4] a($:-1:1,1) = [8;7] a($) = 123 a(1,%pi) = 1 // equivalent to a(1,3)=1 // x = 'test' x([4 5]) = ['4','5'] // b = [1/%s, (%s+1)/(%s-1)] b(1,1) = 0 b(1,$) = b(1,$)+1 b(2) = [1 2] // the numerator
List or Tlist cases:
See also
- extraction — matrix and list entry extraction
- 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 | ||
| << ind2sub | Elementary Functions | isempty >> |