Cell Arrays
一个细胞与索引数据控制数组是一种数据类型ainers 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 asc{1}
to return42
andc{3}
to return"abcd"
. For more information, seeAccess 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, usetable
ortimetable
instead. If your data is text only, usestring
.
Functions
Topics
- What Is a Cell Array?
一个细胞与索引数据控制数组是一种数据类型ainers 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.