Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Одиноков / МиИПиС_асп_13г / MATLAB_R2013a_Выбор.doc
Скачиваний:
32
Добавлен:
15.04.2015
Размер:
4.03 Mб
Скачать
  • R2013a>MATLAB>Language Fundamentals>Data Types>Cell Arrays

  • Add Cells to a Cell Array

This example shows how to add cells to a cell array.

Create a 1-by-3 cell array:

C = {1, 2, 3};

Assign data to a cell outside the current dimensions:

C{4,4} = 44

MATLAB® expands the cell array to a rectangle that includes the specified subscripts. Any intervening cells contain empty arrays:

C =

[1] [2] [3] []

[] [] [] []

[] [] [] []

[] [] [] [44]

Add cells without specifying a value by assigning an empty array as the contents of a cell:

C{5,5} = []

C is now a 5-by-5 cell array:

C =

[1] [2] [3] [] []

[] [] [] [] []

[] [] [] [] []

[] [] [] [44] []

[] [] [] [] []

For related examples, see:

  • Access Data in a Cell Array (R2013a>MATLAB>Language Fundamentals>Matrices and Arrays>Indexing)

  • Combine Cell Arrays (R2013a>MATLAB>Language Fundamentals>Data Types>Cell Arrays)

  • Delete Data from a Cell Array (R2013a>MATLAB>Language Fundamentals>Data Types>Cell Arrays)

  • R2013a>MATLAB>Language Fundamentals>Data Types>Cell Arrays

  • Delete Data from a Cell Array

This example shows how to remove data from individual cells, and how to delete entire cells from a cell array. To run the code in this example, create a 3-by-3 cell array:

C = {1, 2, 3; 4, 5, 6; 7, 8, 9};

Delete the contents of a particular cell by assigning an empty array to the cell, using curly braces for content indexing, {}:

C{2,2} = []

This code returns

C =

[1] [2] [3]

[4] [] [6]

[7] [8] [9]

Delete sets of cells using standard array indexing with smooth parentheses, (). For example, this command

C(2,:) = []

removes the second row of C:

C =

[1] [2] [3]

[7] [8] [9]

For related examples, see:

  • Add Cells to a Cell Array (R2013a>MATLAB>Language Fundamentals>Data Types>Cell Arrays)

  • Access Data in a Cell Array (R2013a>MATLAB>Language Fundamentals>Matrices and Arrays>Indexing)

  • R2013a>MATLAB>Language Fundamentals>Data Types>Cell Arrays

  • Combine Cell Arrays

This example shows how to combine cell arrays by concatenation or nesting. To run the code in this example, create several cell arrays with the same number of columns:

C1 = {1, 2, 3};

C2 = {'A', 'B', 'C'};

C3 = {10, 20, 30};

Concatenate cell arrays with the array concatenation operator, []. In this example, vertically concatenate the cell arrays by separating them with semicolons:

C4 = [C1; C2; C3] % Массив ячеек как объединение их содержимого.

C4 is a 3-by-3 cell array:

C4 =

[ 1] [ 2] [ 3]

'A' 'B' 'C'

[10] [20] [30]

Create a nested cell array with the cell array construction operator, {}:

C5 = {C1; C2; C3} % Массив ячеек как объединение ячеек.

C5 is a 3-by-1 cell array, where each cell contains a cell array:

C5 =

{1x3 cell}

{1x3 cell}

{1x3 cell}

For more information, see Concatenating Matrices (R2013a>MATLAB>Language Fundamentals>Matrices and Arrays>Array Creation and Concatenation>Creating and Concatenating Matrices).