0
0
MATLABdata~10 mins

Cell array indexing (curly vs parentheses) in MATLAB - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Cell array indexing (curly vs parentheses)
Start with cell array
Use parentheses ()
Returns a cell array subset
Use curly braces {}
Returns content inside cells
Use content directly in expressions
This flow shows how using parentheses returns cells themselves, while curly braces extract the content inside cells.
Execution Sample
MATLAB
C = {10, 20; 30, 40};
a = C(1,2);
b = C{1,2};
Create a 2x2 cell array C, then extract a cell with () and content with {}.
Execution Table
StepExpressionResult TypeResult ValueExplanation
1C = {10, 20; 30, 40};cell array{{10}, {20}; {30}, {40}}Create 2x2 cell array with numbers inside cells
2a = C(1,2);cell array{{20}}Parentheses return a 1x1 cell array containing the cell at (1,2)
3b = C{1,2};double20Curly braces return the content inside the cell at (1,2)
4a is a cell array, b is a doubletype checkisa(a,'cell')=true, isa(b,'double')=trueShows difference in output types
💡 Execution ends after assigning a and b with different indexing methods.
Variable Tracker
VariableStartAfter Step 2After Step 3Final
Cundefined{{10}, {20}; {30}, {40}}{{10}, {20}; {30}, {40}}{{10}, {20}; {30}, {40}}
aundefined{{20}}{{20}}{{20}}
bundefinedundefined2020
Key Moments - 2 Insights
Why does a = C(1,2) return a cell array but b = C{1,2} returns a number?
Because parentheses () return a subset of the cell array itself (still cells), while curly braces {} extract the actual content inside the cell. See execution_table rows 2 and 3.
Can I use the content from b directly in calculations but not from a?
Yes, b holds the actual number 20, so you can use it in math. a is a cell array containing a cell, so you must extract content first. See execution_table row 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the type of variable 'a' after step 2?
Achar
Bcell array
Cdouble
Dlogical
💡 Hint
Check execution_table row 2, column 'Result Type' shows 'cell array'.
At which step does variable 'b' get assigned the numeric value 20?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at execution_table row 3 where b is assigned 20.
If you want to get a cell array containing the first row of C, which indexing should you use?
AC(1,:)
BC{1,:}
CC{:,1}
DC(:,1)
💡 Hint
Parentheses () return cell arrays subsets, curly braces {} extract content. See concept_flow.
Concept Snapshot
Cell array indexing:
- Use parentheses () to get cells (cell array output)
- Use curly braces {} to get content inside cells
- () returns a cell array subset
- {} returns the actual data inside cells
- Use {} when you want to work with the data directly
Full Transcript
This example shows how MATLAB cell arrays can be indexed in two ways. Using parentheses () returns a subset of the cell array itself, so the result is still a cell array. Using curly braces {} extracts the content inside the cell, returning the actual data stored. For example, C(1,2) returns a 1x1 cell array containing the cell at row 1, column 2, while C{1,2} returns the number inside that cell. This difference is important because you can only use the extracted content directly in calculations. The execution table traces these steps and shows the types and values after each indexing operation.