matlab\ops – Операторы и специальные символы
Arithmetic operators.
<plus> - Plus +
+ Plus.
X + Y adds matrices X and Y. X and Y must have the same
dimensions unless one is a scalar (a 1-by-1 matrix).
A scalar can be added to anything.
C = PLUS(A,B) is called for the syntax 'A + B' when A or B is an
object.
Overloaded methods:
timeseries/plus
gf/plus
dynamicsys/plus
InputOutputModel/plus
codistributed/plus
LagOp/plus
fints/plus
idmodel/plus
designdev/plus
cvdata/plus
uss/plus
umat/plus
ufrd/plus
ndlft/plus
icsignal/plus
atom/plus
sym/plus
laurpoly/plus
laurmat/plus
<uplus> - Unary plus +
+ Unary plus.
+A for numeric arrays is A.
B = UPLUS(A) is called for the syntax '+A' when A is an object.
Overloaded methods:
codistributed/uplus
fints/uplus
uss/uplus
umat/uplus
ufrd/uplus
ndlft/uplus
icsignal/uplus
atom/uplus
<minus> - Minus -
- Minus.
X - Y subtracts matrix Y from X. X and Y must have the same
dimensions unless one is a scalar. A scalar can be subtracted
from anything.
C = MINUS(A,B) is called for the syntax 'A - B' when A or B is an
object.
Overloaded methods:
timeseries/minus
gf/minus
codistributed/minus
LagOp/minus
fints/minus
idmodel/minus
sweepset/minus
cvdata/minus
uss/minus
umat/minus
ufrd/minus
ndlft/minus
icsignal/minus
atom/minus
sym/minus
laurpoly/minus
laurmat/minus
<uminus> - Unary minus -
- Unary minus.
-A negates the elements of A.
B = UMINUS(A) is called for the syntax '-A' when A is an object.
Overloaded methods:
codistributed/uminus
gf/uminus
fints/uminus
idss/uminus
idpoly/uminus
idgrey/uminus
idarx/uminus
uss/uminus
umat/uminus
ufrd/uminus
ndlft/uminus
icsignal/uminus
atom/uminus
laurpoly/uminus
laurmat/uminus
<mtimes> - Matrix multiply *
* Matrix multiply.
X*Y is the matrix product of X and Y. Any scalar (a 1-by-1 matrix)
may multiply anything. Otherwise, the number of columns of X must
equal the number of rows of Y.
C = MTIMES(A,B) is called for the syntax 'A * B' when A or B is an
object.
See also times.
Overloaded methods:
codistributed/mtimes
timeseries/mtimes
gf/mtimes
dynamicsys/mtimes
InputOutputModel/mtimes
LagOp/mtimes
fints/mtimes
idmodel/mtimes
localpoly/mtimes
cvdata/mtimes
uss/mtimes
umat/mtimes
ufrd/mtimes
ndlft/mtimes
icsignal/mtimes
atom/mtimes
laurpoly/mtimes
laurmat/mtimes
Reference page in Help browser
doc mtimes
<times> - Array multiply .*
.* Array multiply.
X.*Y denotes element-by-element multiplication. X and Y
must have the same dimensions unless one is a scalar.
A scalar can be multiplied into anything.
C = TIMES(A,B) is called for the syntax 'A .* B' when A or B is an
object.
See also mtimes.
Overloaded methods:
codistributed/times
timeseries/times
gf/times
dynamicsys/times
DynamicSystem/times
fints/times
cvdata/times
categorical/times
<mpower> - Matrix power ^
^ Matrix power.
Z = X^y is X to the y power if y is a scalar and X is square. If y
is an integer greater than one, the power is computed by repeated
squaring. For other values of y the calculation involves
eigenvalues and eigenvectors.
Z = x^Y is x to the Y power if Y is a square matrix and x is a scalar.
Computed using eigenvalues and eigenvectors.
Z = X^Y, where both X and Y are matrices, is an error.
C = MPOWER(A,B) is called for the syntax 'A ^ B' when A or B is an
object.
See also power.
Overloaded methods:
InputOutputModel/mpower
gf/mpower
idmodel/mpower
umat/mpower
atom/mpower
laurpoly/mpower
<power> - Array power .^
.^ Array power.
Z = X.^Y denotes element-by-element powers. X and Y
must have the same dimensions unless one is a scalar.
A scalar can operate into anything.
C = POWER(A,B) is called for the syntax 'A .^ B' when A or B is an
object.
See also mpower, nthroot, realpow.
Overloaded methods:
codistributed/power
gf/power
fints/power
xregcovariance/power
Reference page in Help browser
doc power
<mldivide> - Backslash or left matrix divide \
\ Backslash or left matrix divide.
A\B is the matrix division of A into B, which is roughly the
same as INV(A)*B , except it is computed in a different way.
If A is an N-by-N matrix and B is a column vector with N
components, or a matrix with several such columns, then
X = A\B is the solution to the equation A*X = B. A warning
message is printed if A is badly scaled or nearly singular.
A\EYE(SIZE(A)) produces the inverse of A.
If A is an M-by-N matrix with M < or > N and B is a column
vector with M components, or a matrix with several such columns,
then X = A\B is the solution in the least squares sense to the
under- or overdetermined system of equations A*X = B. The
effective rank, K, of A is determined from the QR decomposition
with pivoting. A solution X is computed which has at most K
nonzero components per column. If K < N this will usually not
be the same solution as PINV(A)*B. A\EYE(SIZE(A)) produces a
generalized inverse of A.
C = MLDIVIDE(A,B) is called for the syntax 'A \ B' when A or B is an
object.
See also ldivide, rdivide, mrdivide.
Overloaded methods:
codistributed/mldivide
timeseries/mldivide
gf/mldivide
DynamicSystem/mldivide
LagOp/mldivide
uss/mldivide
umat/mldivide
ufrd/mldivide
ndlft/mldivide
atom/mldivide
laurpoly/mldivide
Reference page in Help browser
doc mldivide
<mrdivide> - Slash or right matrix divide /
/ Slash or right matrix divide.
A/B is the matrix division of B into A, which is roughly the
same as A*INV(B) , except it is computed in a different way.
More precisely, A/B = (B'\A')'. See MLDIVIDE for details.
C = MRDIVIDE(A,B) is called for the syntax 'A / B' when A or B is an
object.
See also mldivide, rdivide, ldivide.
Overloaded methods:
codistributed/mrdivide
timeseries/mrdivide
gf/mrdivide
DynamicSystem/mrdivide
LagOp/mrdivide
fints/mrdivide
uss/mrdivide
umat/mrdivide
ufrd/mrdivide
ndlft/mrdivide
atom/mrdivide
laurpoly/mrdivide
Reference page in Help browser
doc mrdivide
<ldivide> - Left array divide .\
.\ Left array divide.
A.\B denotes element-by-element division. A and B
must have the same dimensions unless one is a scalar.
A scalar can be divided with anything.
C = LDIVIDE(A,B) is called for the syntax 'A .\ B' when A or B is an
object.
See also rdivide, mrdivide, mldivide.
Overloaded methods:
codistributed/ldivide
timeseries/ldivide
gf/ldivide
Reference page in Help browser
doc ldivide
<rdivide> - Right array divide ./
./ Right array divide.
A./B denotes element-by-element division. A and B
must have the same dimensions unless one is a scalar.
A scalar can be divided with anything.
C = RDIVIDE(A,B) is called for the syntax 'A ./ B' when A or B is an
object.
See also ldivide, mldivide, mrdivide.
Overloaded methods:
codistributed/rdivide
timeseries/rdivide
gf/rdivide
fints/rdivide
Reference page in Help browser
doc rdivide
<idivide> - Integer division with rounding option.
IDIVIDE Integer division with rounding option.
C = IDIVIDE(A,B,OPT) is the same as A ./ B for integer classes except
that fractional quotients are rounded to integers using the optional
rounding mode specified by OPT. The default rounding mode is 'fix'.
A and B must be real and must have the same dimensions unless one is a
scalar. At least one of the arguments A and B must belong to an
integer class, and the other must belong to the same integer class or
be a scalar double. The result C belongs to the integer class.
C = IDIVIDE(A,B) and
C = IDIVIDE(A,B,'fix') are the same as A./B except that fractional
quotients are rounded toward zero to the nearest integers.
C = IDIVIDE(A,B,'round') is the same as A./B for integer classes.
Fractional quotients are rounded to the nearest integers.
C = IDIVIDE(A,B,'floor') is the same as A./B except that fractional
quotients are rounded toward negative infinity to the nearest integers.
C = IDIVIDE(A,B,'ceil') is the same as A./B except that the fractional
quotients are rounded toward infinity to the nearest integers.
Examples
a = int32([-2 2]);
b = int32(3);
idivide(a,b) returns [0 0]
idivide(a,b,'floor') returns [-1 0]
idivide(a,b,'ceil') returns [0 1]
idivide(a,b,'round') returns [-1 1]
See also ldivide, rdivide, mldivide, mrdivide.
Reference page in Help browser
doc idivide
<kron> - Kronecker tensor product
KRON Kronecker tensor product.
KRON(X,Y) is the Kronecker tensor product of X and Y.
The result is a large matrix formed by taking all possible
products between the elements of X and those of Y. For
example, if X is 2 by 3, then KRON(X,Y) is
[ X(1,1)*Y X(1,2)*Y X(1,3)*Y
X(2,1)*Y X(2,2)*Y X(2,3)*Y ]
If either X or Y is sparse, only nonzero elements are multiplied
in the computation, and the result is sparse.
Class support for inputs X,Y:
float: double, single
Reference page in Help browser
doc kron
Relational operators.
<eq> - Equal ==
== Equal.
A == B does element by element comparisons between A and B
and returns a matrix of the same size with elements set to logical 1
where the relation is true and elements set to logical 0 where it is
not. A and B must have the same dimensions unless one is a
scalar. A scalar can be compared with any size array.
C = EQ(A,B) is called for the syntax 'A == B' when A or B is an
object.
Overloaded methods:
opaque/eq
codistributed/eq
handle/eq
MException/eq
scribehandle/eq
timer/eq
serial/eq
timeseries/eq
instrument/eq
gf/eq
daqdevice/eq
daqchild/eq
fints/eq
imaqdevice/eq
imaqchild/eq
iviconfigurationstore/eq
icgroup/eq
xregpointer/eq
cglookuptwo/eq
xregcovariance/eq
sweepset/eq
opcroot/eq
icsignal/eq
sgmltag/eq
rptcp/eq
rptsp/eq
fdspec/eq
fdmeas/eq
fdline/eq
fdax/eq
ordinal/eq
nominal/eq
categorical/eq
vrworld/eq
vrnode/eq
vrfigure/eq
laurpoly/eq
laurmat/eq
Reference page in Help browser
doc eq
<ne> - Not equal ~=
~= Not equal.
A ~= B does element by element comparisons between A and B
and returns a matrix of the same size with elements set to logical 1
where the relation is true and elements set to logical 0 where it is
not. A and B must have the same dimensions unless one is a
scalar. A scalar can be compared with any size array.
C = NE(A,B) is called for the syntax 'A ~= B' when A or B is an
object.
Overloaded methods:
opaque/ne
codistributed/ne
handle/ne
MException/ne
scribehandle/ne
timer/ne
serial/ne
instrument/ne
gf/ne
daqdevice/ne
daqchild/ne
imaqdevice/ne
imaqchild/ne
iviconfigurationstore/ne
icgroup/ne
xregpointer/ne
xregcovariance/ne
sweepset/ne
opcroot/ne
sgmltag/ne
rptcp/ne
rptsp/ne
ordinal/ne
nominal/ne
categorical/ne
vrworld/ne
vrnode/ne
vrfigure/ne
laurpoly/ne
laurmat/ne
Reference page in Help browser
doc ne
<lt> - Less than <
< Less than.
A < B does element by element comparisons between A and B
and returns a matrix of the same size with elements set to logical 1
where the relation is true and elements set to logical 0 where it is
not. A and B must have the same dimensions unless one is a
scalar. A scalar can be compared with any size array.
C = LT(A,B) is called for the syntax 'A < B' when A or B is an
object.
Overloaded methods:
codistributed/lt
handle/lt
sweepset/lt
ordinal/lt
Reference page in Help browser
doc lt
<gt> - Greater than >
> Greater than.
A > B does element by element comparisons between A and B
and returns a matrix of the same size with elements set to logical 1
where the relation is true and elements set to logical 0 where it is
not. A and B must have the same dimensions unless one is a
scalar. A scalar can be compared with any size array.
C = GT(A,B) is called for the syntax 'A > B' when A or B is an
object.
Overloaded methods:
codistributed/gt
handle/gt
sweepset/gt
ordinal/gt
Reference page in Help browser
doc gt
<le> - Less than or equal <=
<= Less than or equal.
A <= B does element by element comparisons between A and B
and returns a matrix of the same size with elements set to logical 1
where the relation is true and elements set to logical 0 where it is
not. A and B must have the same dimensions unless one is a
scalar. A scalar can be compared with any size array.
C = LE(A,B) is called for the syntax 'A <= B' when A or B is an
object.
Overloaded methods:
codistributed/le
handle/le
sweepset/le
ordinal/le
Reference page in Help browser
doc le
<ge> - Greater than or equal >=
>= Greater than or equal.
A >= B does element by element comparisons between A and B
and returns a matrix of the same size with elements set to logical 1
where the relation is true and elements set to logical 0 where it is
not. A and B must have the same dimensions unless one is a
scalar. A scalar can be compared with any size array.
C = GE(A,B) is called for the syntax 'A >= B' when A or B is an
object.
Overloaded methods:
codistributed/ge
handle/ge
sweepset/ge
ordinal/ge
Reference page in Help browser
doc ge
Logical operators.
<relop> - Short-circuit logical AND &&
Relational operators.
< > Relational operators.
The six relational operators are <, <=, >, >=, ==, and ~=.
A < B does element by element comparisons between A and B
and returns a matrix of the same size with elements set to logical
1 (TRUE) where the relation is true and elements set to logical 0
(FALSE) where it is not. A and B must have the same dimensions
(or one can be a scalar).
& Element-wise Logical AND.
A & B is a matrix whose elements are logical 1 (TRUE) where both A
and B have non-zero elements, and logical 0 (FALSE) where either has
a zero element. A and B must have the same dimensions (or one can
be a scalar).
&& Short-Circuit Logical AND.
A && B is a scalar value that is the logical AND of scalar A and B.
This is a "short-circuit" operation in that MATLAB evaluates B only
if the result is not fully determined by A. For example, if A equals
0, then the entire expression evaluates to logical 0 (FALSE), regard-
less of the value of B. Under these circumstances, there is no need
to evaluate B because the result is already known.
| Element-wise Logical OR.
A | B is a matrix whose elements are logical 1 (TRUE) where either
A or B has a non-zero element, and logical 0 (FALSE) where both have
zero elements. A and B must have the same dimensions (or one can
be a scalar).
|| Short-Circuit Logical OR.
A || B is a scalar value that is the logical OR of scalar A and B.
This is a "short-circuit" operation in that MATLAB evaluates B only
if the result is not fully determined by A. For example, if A equals
1, then the entire expression evaluates to logical 1 (TRUE), regard-
less of the value of B. Under these circumstances, there is no need
to evaluate B because the result is already known.
~ Logical complement (NOT).
~A is a matrix whose elements are logical 1 (TRUE) where A has zero
elements, and logical 0 (FALSE) where A has non-zero elements.
xor Exclusive OR.
xor(A,B) is logical 1 (TRUE) where either A or B, but not both, is
non-zero. See XOR.
<relop> - Short-circuit logical OR ||
Relational operators.
< > Relational operators.
The six relational operators are <, <=, >, >=, ==, and ~=.
A < B does element by element comparisons between A and B
and returns a matrix of the same size with elements set to logical
1 (TRUE) where the relation is true and elements set to logical 0
(FALSE) where it is not. A and B must have the same dimensions
(or one can be a scalar).
& Element-wise Logical AND.
A & B is a matrix whose elements are logical 1 (TRUE) where both A
and B have non-zero elements, and logical 0 (FALSE) where either has
a zero element. A and B must have the same dimensions (or one can
be a scalar).
&& Short-Circuit Logical AND.
A && B is a scalar value that is the logical AND of scalar A and B.
This is a "short-circuit" operation in that MATLAB evaluates B only
if the result is not fully determined by A. For example, if A equals
0, then the entire expression evaluates to logical 0 (FALSE), regard-
less of the value of B. Under these circumstances, there is no need
to evaluate B because the result is already known.
| Element-wise Logical OR.
A | B is a matrix whose elements are logical 1 (TRUE) where either
A or B has a non-zero element, and logical 0 (FALSE) where both have
zero elements. A and B must have the same dimensions (or one can
be a scalar).
|| Short-Circuit Logical OR.
A || B is a scalar value that is the logical OR of scalar A and B.
This is a "short-circuit" operation in that MATLAB evaluates B only
if the result is not fully determined by A. For example, if A equals
1, then the entire expression evaluates to logical 1 (TRUE), regard-
less of the value of B. Under these circumstances, there is no need
to evaluate B because the result is already known.
~ Logical complement (NOT).
~A is a matrix whose elements are logical 1 (TRUE) where A has zero
elements, and logical 0 (FALSE) where A has non-zero elements.
xor Exclusive OR.
xor(A,B) is logical 1 (TRUE) where either A or B, but not both, is
non-zero. See XOR.
<and> - Element-wise logical AND &
& Logical AND.
A & B performs a logical AND of arrays A and B and returns an array
containing elements set to either logical 1 (TRUE) or logical 0
(FALSE). An element of the output array is set to 1 if both input
arrays contain a non-zero element at that same array location.
Otherwise, that element is set to 0. A and B must have the same
dimensions unless one is a scalar.
C = AND(A,B) is called for the syntax 'A & B' when A or B is an
object.
Note that there are two logical AND operators in MATLAB. The &
operator performs an element-by-element AND between matrices, while
the && operator performs a short-circuit AND between scalar values.
These operations are explained in the MATLAB Programming documentation
on logical operators, under the topic of Basic Program Components.
See also relop, or, xor, not.
Overloaded methods:
codistributed/and
conswitch/and
conrange/and
conboolean/and
conbase/and
Reference page in Help browser
doc and
<or> - Element-wise logical OR |
| Logical OR.
A | B performs a logical OR of arrays A and B and returns an array
containing elements set to either logical 1 (TRUE) or logical 0
(FALSE). An element of the output array is set to 1 if either input
array contains a non-zero element at that same array location.
Otherwise, that element is set to 0. A and B must have the same
dimensions unless one is a scalar.
C = OR(A,B) is called for the syntax 'A | B' when A or B is an
object.
Note that there are two logical OR operators in MATLAB. The |
operator performs an element-by-element OR between matrices, while
the || operator performs a short-circuit OR between scalar values.
These operations are explained in the MATLAB Programming documentation
on logical operators, under the topic of Basic Program Components.
See also relop, and, xor, not
Overloaded methods:
codistributed/or
conrange/or
conboolean/or
conbase/or
Reference page in Help browser
doc or
<not> - Logical NOT ~
~ Logical NOT.
~A performs a logical NOT of input array A, and returns an array
containing elements set to either logical 1 (TRUE) or logical 0 (FALSE).
An element of the output array is set to 1 if A contains a zero value
element at that same array location. Otherwise, that element is set to
0.
B = NOT(A) is called for the syntax '~A' when A is an object.
~ can also be used to ignore input arguments in a function definition,
and output arguments in a function call. See "help punct"
Overloaded methods:
codistributed/not
contable2/not
contable1/not
conlinear/not
conellipsoid/not
conboolean/not
conbase/not
Reference page in Help browser
doc not
<punct> - Ignore function argument or output ~
Punctuation.
. Decimal point. 325/100, 3.25 and .325e1 are all the same.
. Array operations. Element-by-element multiplicative operations
are obtained using .* , .^ , ./ , .\ or .'. For example,
C = A ./ B is the matrix with elements c(i,j) = a(i,j)/b(i,j).
. Field access. A.field and A(i).field, when A is a structure, access
the contents of the field with the name "field". If A isn't a
scalar structure, this produces a comma separated list (see LISTS).
You can nest structure access as in X(2).field(3).name. You can
also combine structure, cell array, and parentheses subscripting
for arrays stored in the structure (see PAREN).
.. Parent directory. See CD.
... Continuation. Three or more periods at the end of a line continue
the current command or function call onto the next line. Three or
more periods before the end of a line cause MATLAB to ignore the
remaining text on the current line and continue the command or
function call onto the next line. This effectively makes a comment
out of anything on the current line that follows the periods.
, Comma. The comma is used to separate matrix subscripts
and arguments to functions. It is also used to separate
statements in multi-statement lines. In this situation,
It may be replaced by a semicolon to suppress printing.
; Semicolon. The semicolon is used inside brackets to indicate
the ends of the rows of a matrix. It is also used after an
expression or statement to suppress printing.
% Percent. The percent symbol is used to begin comments.
Logically, it serves as an end-of-line character. Any
following text on the line is ignored or printed by the
HELP system.
%{ Percent-OpenBrace. This symbol begins a block comment. Use this
symbol to enter a multiline comment. MATLAB ignores everything
within a block comment during execution including any program code.
The %{ symbol must appear alone on the line that precedes the comment.
You can also use block comments to comment out code in the middle
of a multi-line statement. You cannot do this with the single-line
comment operator, %. For example, the statement on the left below
Is valid, while the one on the right is not:
addpath(... addpath( ...
'dir1', ... 'dir1', ...
%{ % 'dir2', ...
'dir2', ... 'dir3'
%} )
'dir3' ...
)
%} Percent-CloseBrace. This symbol ends a block comment. Use this
symbol to enter a multiline comment. MATLAB ignores everything
within a block comment during execution including any program code.
The %} symbol must appear alone on the line that follows the comment.
See the %{ symbol, above.
! Exclamation point. Any text following the '!' is issued
as a command to the underlying computer operating system.
On the PC, adding & to the end of the ! command line, as in
!dir &
causes the output to appear in a separate window and for the window
to remain open after the command completes.
' Transpose. X' is the complex conjugate transpose of X.
X.' is the non-conjugate transpose.
' Quote. 'ANY TEXT' is a vector whose components are the
ASCII codes for the characters. A quote within the text
is indicated by two quotes. For example: 'Don''t forget.'
= Assignment. B = A stores the elements of A in B.
@ At. The at symbol is used to create a function_handle.
It is also used at the beginning of directory names that contain
matlab object methods and the constructor for the object, e.g.
the directory @inline contains the constructor inline.m for the
inline object and all methods for inline objects.
~ The tilde character can be used in function definitions to
represent an input argument that is unused within the function.
It can also be used to indicate that an output argument of a
function call is to ignored. In this case, it must appear
within [ ] and separated by commas from any other arguments.
See also relop, colon, lists, paren, cd, function_handle.
<xor> - Logical EXCLUSIVE OR
XOR Logical EXCLUSIVE OR.
XOR(S,T) is the logical symmetric difference of elements S and T.
The result is logical 1 (TRUE) where either S or T, but not both, is
nonzero. The result is logical 0 (FALSE) where S and T are both zero
or nonzero. S and T must have the same dimensions (or one can be a
scalar).
See also or, relop.
Overloaded methods:
codistributed/xor
conbase/xor
Reference page in Help browser
doc xor
<any> - True if any element of vector is nonzero
ANY True if any element of a vector is a nonzero number or is
logical 1 (TRUE). ANY ignores entries that are NaN (Not a Number).
For vectors, ANY(V) returns logical 1 (TRUE) if any of the
elements of the vector is a nonzero number or is logical 1 (TRUE).
Otherwise it returns logical 0 (FALSE). For matrices, ANY(X)
operates on the columns of X, returning a row vector of logical 1's
and 0's. For multi-dimensional arrays, ANY(X) operates on the
first non-singleton dimension.
ANY(X,DIM) works down the dimension DIM. For example, ANY(X,1)
works down the first dimension (the rows) of X.
See also all.
Overloaded methods:
codistributed/any
gf/any
Reference page in Help browser
doc any
<all> - True if all elements of vector are nonzero
ALL True if all elements of a vector are nonzero.
For vectors, ALL(V) returns logical 1 (TRUE) if none of the elements
of the vector are zero. Otherwise it returns logical 0 (FALSE). For
matrices, ALL(X) operates on the columns of X, returning a row vector
of logical 1's and 0's. For N-D arrays, ALL(X) operates on the first
non-singleton dimension.
ALL(X,DIM) works down the dimension DIM. For example, ALL(X,1)
works down the first dimension (the rows) of X.
See also any.
Overloaded methods:
codistributed/all
gf/all
Reference page in Help browser
doc all
Special characters.
<colon> - Colon :
: Colon.
J:K is the same as [J, J+1, ..., K].
J:K is empty if J > K.
J:D:K is the same as [J, J+D, ..., J+m*D] where m = fix((K-J)/D).
J:D:K is empty if D == 0, if D > 0 and J > K, or if D < 0 and J < K.
COLON(J,K) is the same as J:K and COLON(J,D,K) is the same as J:D:K.
The colon notation can be used to pick out selected rows, columns
and elements of vectors, matrices, and arrays. A(:) is all the
elements of A, regarded as a single column. On the left side of an
assignment statement, A(:) fills A, preserving its shape from before.
A(:,J) is the J-th column of A. A(J:K) is [A(J),A(J+1),...,A(K)].
A(:,J:K) is [A(:,J),A(:,J+1),...,A(:,K)] and so on.
The colon notation can be used with a cell array to produce a comma-
separated list. C{:} is the same as C{1},C{2},...,C{end}. The comma
separated list syntax is valid inside () for function calls, [] for
concatenation and function return arguments, and inside {} to produce
a cell array. Expressions such as S(:).name produce the comma separated
list S(1).name,S(2).name,...,S(end).name for the structure S.
For the use of the colon in the FOR statement, See FOR.
For the use of the colon in a comma separated list, See VARARGIN.
Overloaded methods:
distributed/colon
codistributor2dbc/colon
codistributor1d/colon
codistributed/colon
sym/colon
Reference page in Help browser
doc colon
<paren> - Parentheses and subscripting ( )
Parentheses, braces, and brackets.
( ) Parentheses are used to indicate precedence in arithmetic
expressions and to enclose arguments of functions in the usual
way. They are used to enclose subscripts of vectors and matrices
in a manner somewhat more general than the usual way. If X and V
are vectors, then X(V) is the concatenation of X(V(1)), X(V(2)),
..., X(V(N)), where the size of X(V) is 1xN for a row vector X,
or Nx1 for a column vector X. The components of V must be integers
and are used as subscripts. An error occurs if any such subscript
is less than 1 or greater than the dimension of X.
Parenthesis can also enclose logical (or 0-1) subscripts.
If V is logical, the non-zero elements of V define a mask into the
array X. Logical arrays are produced by the relational and logical
operators or by the LOGICAL command. Parentheses are supported by all
the MATLAB data types including the traditional double precision
arrays as well as the structure, cell, and character arrays.
Some examples:
X(3) is the third element of X.
X([1 2 3]) is the first three elements of X.
If X has N components, X(N:-1:1) reverses them.
X(X>0.5) returns those elements of X that are > 0.5.
The same indirect subscripting is used in matrices and arrays.
If V has M components and W has N components, then A(V,W) is the
M-by-N matrix formed from the elements of A whose subscripts are
the elements of V and W. For example, A([1,5],:) = A([5,1],:)
interchanges rows 1 and 5 of A.
.() Dot-parentheses are used to reference a structure using a variable
for the fieldname. The fieldname is called 'dynamic' because the
name is established at runtime. The syntax for referencing a
structure S with dynamic fieldname f is
S.(f)
The following example results in aVal getting the value stored in
S.fieldtwo, that is, 2:
S.field_one = 1;
S.field_two = 2;
fieldname = 'field_two';
aVal = S.(fieldname);
The next example shows a function that accepts two inputs:
the first (account_id) a dynamic fieldname, and the second
(year) an index into that field:
function record = get_acct_summary(account_id, year)
record = clientinfo.(account_id)(year);
You can call this function using
acctinfo = get_acct_summary('jmahoney114', 2005);
{ } Braces are used to form cell arrays. They are similar to
brackets [ ] except that nesting levels are preserved.
{magic(3) 6.9 'hello'} is a cell array with three elements.
{magic(3),6.9,'hello'} is the same thing.
{'This' 'is' 'a';'two' 'row' 'cell'} is a 2-by-3 cell array.
The semicolon ends the first row. {1 {2 3} 4} is a 3 element
cell array where element 2 is itself a cell array.
Braces are also used for content addressing of cell arrays.
They act similar to parentheses in this case except that the
contents of the cell are returned.
Some examples:
X{3} is the contents of the third element of X.
X{3}(4,5) is the (4,5) element of those contents.
X{[1 2 3]} is a comma-separated list of the first three
elements of X. It is the same as X{1},X{2},X{3} and makes sense
inside [] ,{}, or in function input or output lists (see LISTS).
You can repeat the content addressing for nested cells so
that X{1}{2} is the contents of the second element of the cell
inside the first cell of X. This also works for nested
structures, as in X(2).field(3).name or combinations of cell arrays
and structures, as in Z{2}.type(3).
[ ] Brackets are used in forming vectors and matrices.
[6.9 9.64 SQRT(-1)] is a vector with three elements
separated by blanks. [6.9, 9.64, sqrt(-1)] is the same
thing. [1+I 2-I 3] and [1 +I 2 -I 3] are not the same.
The first has three elements and the second has five.
[11 12 13; 21 22 23] is a 2-by-3 matrix. The semicolon
ends the first row.
Vectors and matrices can be concatenated with [ ] brackets.
[A B; C] is allowed if the number of rows of A equals
the number of rows of B and the number of columns of A
plus the number of columns of B equals the number of
columns of C. This rule generalizes in a hopefully
obvious way to allow fairly complicated constructions.
N-D arrays within brackets are concatenated along the
first two dimensions. The remaining dimensions must match.
A = [] stores an empty matrix in A. See CLEAR to remove
variables from the current workspace.
For the use of [ and ] on the left of the = in multiple
assignment statements, see LU, EIG, SVD and so on.
See also logical, lists, punct, clear.
<paren> - Brackets [ ]
<paren> - Braces and subscripting { }
<punct> - Function handle creation @
Punctuation.
. Decimal point. 325/100, 3.25 and .325e1 are all the same.
. Array operations. Element-by-element multiplicative operations
are obtained using .* , .^ , ./ , .\ or .'. For example,
C = A ./ B is the matrix with elements c(i,j) = a(i,j)/b(i,j).
. Field access. A.field and A(i).field, when A is a structure, access
the contents of the field with the name "field". If A isn't a
scalar structure, this produces a comma separated list (see LISTS).
You can nest structure access as in X(2).field(3).name. You can
also combine structure, cell array, and parentheses subscripting
for arrays stored in the structure (see PAREN).
.. Parent directory. See CD.
... Continuation. Three or more periods at the end of a line continue
the current command or function call onto the next line. Three or
more periods before the end of a line cause MATLAB to ignore the
remaining text on the current line and continue the command or
function call onto the next line. This effectively makes a comment
out of anything on the current line that follows the periods.
, Comma. The comma is used to separate matrix subscripts
and arguments to functions. It is also used to separate
statements in multi-statement lines. In this situation,