[Solved] Matlab – Why ismember does not work? [closed]


Input A of class cell and input B of class char must be cell arrays of strings, unless one is a string.

This means that every entry in the cell must be a string, and in this case it’s not. If your cell array contains numeric values, or even an empty matrix, you will get this error.

For example, this is fine (cell array of strings, and a char)

ismember({'b','c'},'b');

This is not:

ismember({'b',[1 2]},'b');
ismember({'b',[]},'b');
ismember({'b',NaN},'b');

The most likely one to get mixed into your cell array accidentally is probably the empty matrix. In these cases I always recommend using the debugging tools (dbstop if error is our friend), to doublecheck exactly what is going on. What you think the variable should be or contain, and what it does in fact contain, are not always the same thing.

If it does contain empties, see this question for ideas on how to deal with it.

solved Matlab – Why ismember does not work? [closed]