Cell Arrays
A cell array is a data type with indexed data containers called cells, where each cell can contain any type of data. For instance,
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
Topics
- What Is a Cell Array?
A cell array is a data type with indexed data containers called cells. Each cell can contain any type of data.
- Create Cell Array
Create a cell array by using the
{}
operator or thecell
function. - Access Data in Cell Array
Read and write data from and to a cell array.
- Pass Contents of Cell Arrays to Functions
These examples show several ways to pass data from a cell array to a function that does not recognize cell arrays as inputs.
- Preallocate Memory for Cell Array
Initialize and allocate memory for a cell array.
- Cell vs. Structure Arrays
This example compares cell and structure arrays and shows how to store data in each type of array. Cell and structure arrays enable you to store data of different types and sizes.