MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

ans =


14 12


How to Use the Comma-Separated Lists


Common uses for comma-separated lists are



  • “Constructing Arrays” on page 2-83

  • “Displaying Arrays” on page 2-84

  • “Concatenation” on page 2-84

  • “Function Call Arguments” on page 2-84

  • “Function Return Values” on page 2-85


The following sections provide examples of using comma-separated lists with cell arrays.
Each of these examples applies to MATLAB structures as well.


Constructing Arrays


You can use a comma-separated list to enter a series of elements when constructing a
matrix or array. Note what happens when you insert a list of elements as opposed to
adding the cell itself.


When you specify a list of elements with C{:, 5}, MATLAB inserts the four individual
elements:


A = {'Hello',C{:,5},magic(4)}


A =


'Hello' [34] [36] [38] [40] [4x4 double]


When you specify the C cell itself, MATLAB inserts the entire cell array:


A = {'Hello',C,magic(4)}


A =


'Hello' {4x6 cell} [4x4 double]


Comma-Separated Lists
Free download pdf