With cell arrays you have two methods of indexing namely parenthesis (i.e. (...)) and braces (i.e. {...}).

Lets create a cell array to use for examples:

A = {3,   9,     'a'; 
     'B', [2,4], 0};

Indexing using paranthesis returns a portion of the cell array AS A CELL ARRAY. For example

A(:,3)

returns a 2-by-1 cell array

ans =

    'a'
     0

Indexing using braces return the CONTENTS of that cell, for example

A{1,3}

returns a single character

ans =

a

You can use parenthesis to return a single cell as well but it will still be a cell. You can also use braces to return multiple cells but these return as comma separated lists, which is a bit more advanced.

When assigning to a cell, very similar concepts apply. If you're assigning using parenthesis, then you must assign a cell matrix of the appropriate size:

A(:,1) = {1,1}

if you assign a single value using parenthesis, then you must put it in a cell (i.e. A(1) = 2 will give you an error, so you must do A(1) = {2}). So it's better to use braces as then you are directly affecting the contents of the cell. So it is correct to go

A{1} = 2

this is equivalent to A(1) = {2}. Note that A{1} = {2}, which is what you've done, will not give a error but what is does is nests a cell within your cell which is unlikely what you were after.

Lastly, if you have an matrix inside one of your cells, then Matlab allows you to index directly into that matrix like so:

A{2,2}(1)

ans = 

     3
Answer from Dan on Stack Overflow
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › cell arrays
cell - Cell array - MATLAB
You can use cell to preallocate ... cell array of empty matrices where sz1,...,szN indicate the size of each dimension. For example, cell(2,3) returns a 2-by-3 cell array....
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types
Cell Arrays - MATLAB & Simulink
Read and write data from and to a cell array. ... Create a cell array by using the {} operator or the cell function.
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › cell arrays
Access Data in Cell Array - MATLAB & Simulink
Track how many elements the loop adds to the string array in variable n. n = 0; for k = 1:numel(C) if ischar(C{k}) && contains(C{k},"t") n = n + 1; txt(n) = string(C{k}); end end txt · txt = 1×2 string "first" "longer text in a third location" If you refer to multiple cells using curly brace indexing, MATLAB returns the contents of the cells as a comma-separated list. For example,
🌐
University of Utah
users.cs.utah.edu › ~germain › PPS › Topics › Matlab › cell_arrays.html
Matlab Programming - Cell Arrays
PLEASE NOTE: In Matlab, strings of different lengths are considered different types (even though we don't usually make this distinction) and thus must be stored in cell arrays. Thus 'Jim' is an array of 3 characters. 'Joan' is an array of 4 characters. These are considered different types!
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › data type conversion
num2cell - Convert array to cell array with consistently sized cells - MATLAB
For example, given a 4-by-7-by-3 array, you can specify dim as a positive integer vector to create cell arrays of different dimensions. ... To convert the cell array C back to an array, use the cell2mat function, or use the syntax cat(dim,C{:}) where dim specifies the dimensions.
Top answer
1 of 2
5

With cell arrays you have two methods of indexing namely parenthesis (i.e. (...)) and braces (i.e. {...}).

Lets create a cell array to use for examples:

A = {3,   9,     'a'; 
     'B', [2,4], 0};

Indexing using paranthesis returns a portion of the cell array AS A CELL ARRAY. For example

A(:,3)

returns a 2-by-1 cell array

ans =

    'a'
     0

Indexing using braces return the CONTENTS of that cell, for example

A{1,3}

returns a single character

ans =

a

You can use parenthesis to return a single cell as well but it will still be a cell. You can also use braces to return multiple cells but these return as comma separated lists, which is a bit more advanced.

When assigning to a cell, very similar concepts apply. If you're assigning using parenthesis, then you must assign a cell matrix of the appropriate size:

A(:,1) = {1,1}

if you assign a single value using parenthesis, then you must put it in a cell (i.e. A(1) = 2 will give you an error, so you must do A(1) = {2}). So it's better to use braces as then you are directly affecting the contents of the cell. So it is correct to go

A{1} = 2

this is equivalent to A(1) = {2}. Note that A{1} = {2}, which is what you've done, will not give a error but what is does is nests a cell within your cell which is unlikely what you were after.

Lastly, if you have an matrix inside one of your cells, then Matlab allows you to index directly into that matrix like so:

A{2,2}(1)

ans = 

     3
2 of 2
2

for example:

for i=1:5
    for j=1:3
       A{i,j} = rand(3)
    end
end

should work perfectly fine
just skip the { } on the right side of the =

🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › cell arrays
Add or Delete Cells in Cell Array - MATLAB & Simulink
Cell arrays follow the same basic rules for expansion, concatenation, and deletion as other types of MATLAB® arrays. However, you can index into a cell array in two ways: with curly braces {} to access cell contents or with parentheses () to refer to the cells themselves.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › software engineering › cell-arrays-in-matlab
Cell Arrays in MATLAB - GeeksforGeeks
April 28, 2025 - In MATLAB, cell arrays are a type ... store heterogeneous data into a single array. For example, let us create a cell array which holds the name and age of a person....
🌐
Northwestern University
ece.northwestern.edu › local-apps › matlabhelp › techdoc › matlab_prog › ch13_c11.html
Structures and Cell Arrays (Programming and Data Types)
A cell array is a MATLAB array for which the elements are cells, containers that can hold other MATLAB arrays. For example, one cell of a cell array might contain a real matrix, another an array of text strings, and another a vector of complex values.
🌐
UNL
cse.unl.edu › ~sincovec › Matlab › Lesson 21 › CS211 Lesson 21 - Cell Arrays.htm
CS 211 Lesson 21 Cell Arrays
The cell array · A contains three items: a 1-by-5 character array (a string), a 1-by-3 character array (a string), and a 2-by-4 double array. This example cell array will be used throughout the rest of this lesson to demonstrate cell array syntax and manipulation.
🌐
Cornell Virtual Workshop
cvw.cac.cornell.edu › matlab › tips › cell-struct-arrays
Cornell Virtual Workshop > MATLAB Programming > MATLAB Tips > Cell and Struct Arrays
>> X = cell(0); >> X{1} = 1; >> X{2} = 'Hello World'; >> X{3} = [9949 9967 9973]; >> X >> X = [1] 'Hello World' [1x3 double] If you attempt to print the contents of a cell, MATLAB may either print the actual contents or it may print a shorter representation of a given entry, such as the "[1x3 ...
🌐
EDUCBA
educba.com › home › data science › data science tutorials › matlab tutorial › matlab cell array
Matlab Cell Array | How Cell Array Works in Matlab with Examples?
August 23, 2025 - We can determine whether the array declared is a cell array or not by using Matlab’s iscell () function. It returns a logical value of 1 or 0 depending on the array type in the input argument. If the array is a cell array, it returns logical 1 (True); if not, it returns logical 0(False). Please find the below example which explains the above concept:
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
ScienceDirect
sciencedirect.com › topics › engineering › cell-array
Cell Array - an overview | ScienceDirect Topics
The MATLAB code below illustrates the data structure that is based on the first design using a sample from the fibroblast data set. The cell array will be 517 rows by 5 columns. There is one column for each attribute. One of the columns is itself an array—the expression data for the gene.
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › data type conversion
cell2struct - Convert cell array to structure array - MATLAB
For example, the default value of 1 assigns each row of the cell array to the corresponding field name in fields. Specify 2 to assign each column of the cell array to the corresponding field name. ... The input arguments fields and dim must be compile-time constants.
🌐
TutorialsPoint
tutorialspoint.com › matlab › matlab_cell_arrays.htm
MATLAB - Cell Arrays
In the above example,we first create a sample table T with columns for Name, Age, Height, and Weight. Then, we use the table2cell() function to convert the table T into a cell array C. Finally, we display the contents of the cell array in C. ...
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
Cell Arrays of Character Vectors - MATLAB & Simulink
For example, you can use the strcmp function to compare the contents of C to a character vector. strcmp returns 1 where there is a match and 0 otherwise. ... You can sum over TF to find the number of matches. ... Use TF as logical indices to return the matches in C. If you index using smooth ...
🌐
Matlabsolutions
matlabsolutions.com › documentation › matlab-basics › cell-arrays.php
Cell Arrays - MATLAB & Simulink
... % Create a cell array with different types of data myCellArray = {'MATLAB', 3.14; rand(2, 2), {'Cell', 'Array'}}; % Display the cell array disp('Original Cell Array:'); disp(myCellArray); % Access and display specific elements disp('First ...
🌐
MathWorks
mathworks.com › matlab › external language interfaces › c++ with matlab › call matlab from c++
Create Cell Arrays from C++ - MATLAB & Simulink
A MATLAB® cell array is a container ... the matlab::data::ArrayFactory::createCellArray member function. To create an empty cell array, use createArray<matlab::data::Array>. These examples show how to pass cell arrays to and from MATLAB....
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › cell arrays
cellfun - Apply function to each cell in cell array - MATLAB
The cell arrays C1,...,Cn all must have the same size. ... A = cellfun(___,Name,Value) applies func with additional options specified by one or more Name,Value pair arguments. For example, to return output values in a cell array, specify 'UniformOutput',false.