Q&A
Ask and answer questions to make information more available to wider audiences.
Eli Fyler @elifyler   18, Aug 2023 12:00 AM
accessing elements in a cell array using parentheses () and curly braces {}
What is the difference between accessing elements in a cell array using parentheses () and curly braces {}?
answers 3
 
Answer 1
Chance Boorman @boormanchance   31, Aug 2023 10:35 AM
  However, when you do foo{i} = [] you are assigning to the i-th cell a new value (which is an empty array), thus clearing the contents of that cell.
 
Answer 2
Chance Boorman @boormanchance   31, Aug 2023 10:35 AM
 The syntax of making an element equal to [] with parentheses is a request to delete that element, so when you ask to do foo(i) = [] you remove the i-th cell. It is not an assignment operation, but rather a RemoveElement operation, which uses similar syntax to assignment.
 
Answer 3
Chance Boorman @boormanchance   31, Aug 2023 10:35 AM
Think of cell array as a regular homogenous array, whose elements are all cells. Parentheses (()) simply access the cell wrapper object, while accessing elements using curly bracers ({}) gives the actual object contained within the cell.