To create a cell array use the command:
c
c
e
e
l
l
l
l. For example if we want
A
A
to be
a 3-by-3 cell array, then you should use the following syntax:
“A=
c
c
e
e
l
l
l
l(3,3)”
to get:
“A =
[] [] []
[] [] []
[] [] [] “
That is, the
A
A
has been created to be a 3-by-3 empty cell array. The cells
identification is the same as with matrices. The upper left cell
location/position is (1,1), the next cell in the same row is (1,2) and so on
(single value indexing is allowed also). You can fill a cell array by assigning
data to individual cells one at a time always supporting the correct cell
location/index. Matlab has two default ways to store data (scalars, vectors,
matrices, strings, cells, etc) to cells:
Cell indexing
Enclose the cell subscripts in parentheses using standard array notation.
Enclose the cell contents on the right side of the assignment statement in
curly braces, "{ }" [2]. For example:
“A(1,1) = {[1 4 3; 0 5 8; 7 2 9]}; A(1,2) = {'Anne Smith'};
A(2,1) = {3+7i}; A(2,2) = {-pi:pi/10:pi}; A(2,3)={5};
G=cell(2,1); G(1,1)= {[5 6 9]}; G(2,1)={'Hello World'};
A(3,1) = {G}; A(3,3)={ones(2,2)}; ”
After assigning the cells, in the command window type: “
A
A” to get:
Commentaires sur ces manuels