-4

I have a cell vector with different & redundant company names. And a list of interesting companies. I try to figure out, where in the big matrix the interesting companies appear. I am interested in all appearances. My Code for some reason does not work. the ismember returns always an error.

Comps = Data0(:,7);
for i = 1: length(relCompQ)
    comp = relCompQ{i,1};
    c(:,i) = find(ismember(Comps,comp));
end

errors:

Error using cell/ismember>cellismemberR2012a (line 192) Input A of class cell and input B of class char must be cell arrays of strings, unless one is a string.

Error in cell/ismember (line 56)

[varargout{1:max(1,nargout)}] = cellismemberR2012a(A,B);

Both Vectors have values like: 'Nike', 'Adidas', 'BMW' etc.

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
Ilja
  • 611
  • 3
  • 9
  • 19
  • What error do you get? – 3lectrologos Dec 01 '14 at 11:32
  • 2
    Define what your variables are; and preferably include a smalll example. The code you have posted can't be understood without knowing that – Luis Mendo Dec 01 '14 at 11:32
  • Done: Error using cell/ismember>cellismemberR2012a (line 192) Input A of class cell and input B of class char must be cell arrays of strings, unless one is a string. Error in cell/ismember (line 56) [varargout{1:max(1,nargout)}] = cellismemberR2012a(A,B); Both Vectors have values like: 'Nike', 'Adidas', 'BMW' etc. – Ilja Dec 01 '14 at 12:01

1 Answers1

3

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.

Community
  • 1
  • 1
nkjt
  • 7,825
  • 9
  • 22
  • 28