Home > OS >  Commas in arguments of an array
Commas in arguments of an array

Time:09-22

The second argument in plot puzzles me, removed the "()" after S and no difference. What is the point of it?

enter image description here

CodePudding user response:

In this case where S is a matrix, the arguments that follow are used to take a selection of the matrix in each dimension. The : operator is used to select entries in a range (e.g. 2:end) and when used alone (i.e. :) selects all entries in a range.

The following example selects all rows (:) of the second column (2). Note that S and S(:, :, 1) in this case are identical as this array does not contain a third dimension. I believe this is also the case for your example.

>> S = [1, 2, 3; 4, 5, 6; 7, 8, 9]

S =

     1     2     3
     4     5     6
     7     8     9

>> S(:, 2)

ans =

     2
     5
     8
  • Related