Main Content

Cell Arrays

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 = {42,rand(5),"abcd"}
c =
  1×3 cell array
    {[42]}    {5×5 double}    {["abcd"]}

To access the contents of a cell, enclose indices in curly braces, such as c{1} to return 42 and c{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

expand all

cellCell array

From Cell

cell2matConvert cell array to ordinary array of the underlying data type
cell2structConvert cell array to structure array
cell2tableConvert cell array to table

To Cell

cellstrConvert to cell array of character vectors
mat2cellConvert array to cell array whose cells contain subarrays
num2cellConvert array to cell array with consistently sized cells
struct2cellConvert structure to cell array
table2cellConvert table to cell array

Determine Type

iscellDetermine if input is cell array
iscellstrDetermine if input is cell array of character vectors
celldispDisplay cell array contents
cellfunApply function to each cell in cell array
cellplotGraphically display structure of cell array

Topics

Go to top of page