Stuart’s MATLAB Videos

Watch and Learn

Deleting an element from a cell array

I recently had a situation where I needed to delete an entry from a cell array. When I tried A{3} = [ ], I did not delete the third element, I actual just set it to [ ].

What Loren helped me realize is that cell arrays use () just like regular MATLAB arrays to index into elements of the array, while preserving type of the container. i.e., index into a numeric array with () and you’ll get a numeric array back. Index into a cell array with () and you’ll get a cell array back. {} represents an additional syntax to access the underlying data.

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.