Content Indexing with Curly Braces, {}
Access the contents of cells--the numbers, text, or other data within the cells--by indexing with curly
braces. For example, to access the contents of the last cell of C, use curly braces.
last = C{2,3}
last = 3
last is a numeric variable of type double, because the cell contains a double value.
Similarly, you can index with curly braces to replace the contents of a cell.
C{2,3} = 300
C=2×3 cell array
{'first'}
{'second'}
{'third'}
{[
1]}
{[
2]}
{[ 300]}
You can access the contents of multiple cells by indexing with curly braces. MATLAB® returns the
contents of the cells as a comma-separated list. Because each cell can contain a different type of data,
you cannot assign this list to a single variable. However, you can assign the list to the same number of
variables as cells. MATLAB® assigns to the variables in column order.
Assign contents of four cells of C to four variables.
[r1c1, r2c1, r1c2, r2c2] = C{1:2,1:2}
r1c1 =
'first'
r2c1 = 1
r1c2 =
'second'
r2c2 = 2
If each cell contains the same type of data, you can create a single variable by applying the array
concatenation operator, [], to the comma-separated list.
Concatenate the contents of the second row into a numeric array.
nums = [C{2,:}]
nums = 1×3
1
2
300
See Also
cell | cell2mat
Related Examples
•
“Create Cell Array” on page 12-3
12 Cell Arrays
12-6
Précédent

- 542/1450

Suivant