Search code examples
matlabcell

How to remove a particular set of cells from a cell array?


Suppose I have an array with 10 cells: C{1},C{2},...,C{10}, and let b=[1 2 8], then I want to empty C{1}, C{2} and C{8}, so I tried C{b}=[], but it does't work. Is there any easy way to do it?


Solution

  • C(b) = [] will do it. The {} notation is for addressing the contents of a cell rather than the cell as a member of the array. If you get more than one cell back from the {} notation it returns as a comma separated list which you can't use for indexing. The () notation will get you an index to the actual cells themselves and is thus the correct way to do this.