1

I have an array of cells B. I want to find if one of the cell contains a certain value, in this case [1 1 1440 1920], and if so remove it.

I tried using:

ismember(mat2cell([1 1 1440 1920],1),B)

I got an error saying "Input A of class cell and input B of class cell must be cell arrays of character vectors".

I thought that mat2cell() would give me a cell array. What am I doing wrong?

Is there an easier way to find this component if exist and remove it?

gnovice
  • 125,304
  • 15
  • 256
  • 359
havakok
  • 1,185
  • 2
  • 13
  • 45
  • After looking around a bit more, it appears that this is *basically* a duplicate of [this question](http://stackoverflow.com/q/18740802/52738) (the general solution is the same, just a different set of cell contents to search for), so I'm voting to close. – gnovice Mar 22 '17 at 16:04

1 Answers1

1

Here's how you can do it using cellfun:

B(cellfun(@(c) isequal(c, [1 1 1440 1920]), B)) = [];

The anonymous function is applied to each cell of B, returning a logical index that is true anywhere the contents of a cell is equal to [1 1 1440 1920]. This index is then used to remove those cells.

gnovice
  • 125,304
  • 15
  • 256
  • 359