Main Content

comma, ,

Command separator

Syntax

Description

The comma symbol (,) separates row elements in an array definition, subscripts in an indexing expression, function input and output arguments, and commands entered on the same line. For instance, A(3,2) uses a comma to separate array subscripts in an indexing command.

example

Examples

expand all

You can use commas or spaces to separate the row elements in an array. In practice, spaces are preferred but commas can be useful to visually separate longer expressions.

A = [2 4 6 8]
A = 1×4

     2     4     6     8

B = [1+1, 2+2, 3+3, 4+4]
B = 1×4

     2     4     6     8

Use commas to separate the subscripts in an indexing expression. Use a colon to select an entire array dimension.

A = [1 2 3; 4 5 6; 7 8 9]
A = 3×3

     1     2     3
     4     5     6
     7     8     9

A(1,2)
ans = 
2
A(2,:)
ans = 1×3

     4     5     6

Use commas to separate the input and output arguments in a function call.

A = magic(5);
[Y,I] = max(A,[],2)
Y = 5×1

    24
    23
    22
    21
    25

I = 5×1

     2
     1
     5
     4
     3

Use commas to separate multiple commands on the same line and show output. Alternatively, use semicolons to separate commands on the same line while suppressing output.

A = 2, B = 3, C = A*B
A = 
2
B = 
3
C = 
6

Version History

Introduced before R2006a

See Also

| |