Cell Arrays - MATLAB & Simulink (original) (raw)
Main Content
Arrays that can contain data of varying types and sizes
A cell array is a data type with indexed data containers called cells, where each cell can contain any type of data. For example:
c = 1×3 cell array {[42]} {5×5 double} {["abcd"]}
To access the contents of a cell, enclose indices in curly braces, such asc{1}
to return 42
andc{3}
to return "abcd"
. For more information, see Access Data in Cell Array.
Cell arrays are useful for nontabular data that you want to access by numeric index. If you have tabular data, such as data from a spreadsheet, use table or timetable instead. If your data is text only, use string.
Functions
Create Empty Array
Convert and Check Type
From Cell
cell2mat | Convert cell array to ordinary array of the underlying data type |
---|---|
cell2struct | Convert cell array to structure array |
cell2table | Convert cell array to table |
To Cell
cellstr | Convert to cell array of character vectors |
---|---|
mat2cell | Convert array to cell array whose cells contain subarrays |
num2cell | Convert array to cell array with consistently sized cells |
struct2cell | Convert structure to cell array |
table2cell | Convert table to cell array |
Determine Type
iscell | Determine if input is cell array |
---|---|
iscellstr | Determine if input is cell array of character vectors |
Process Contents
celldisp | Display cell array contents |
---|---|
cellfun | Apply function to each cell in cell array |
cellplot | Graphically display structure of cell array |
Topics
- Access Data in Cell Array
Read and write data from and to a cell array. - Create Cell Array
Create a cell array by using the{}
operator or thecell
function. - Add or Delete Cells in Cell Array
Expand, concatenate, or remove data from a cell array. - Preallocate Memory for Cell Array
Initialize and allocate memory for a cell array.