Matlab-为什么ismember不起作用? [英] Matlab - Why ismember does not work?

查看:543
本文介绍了Matlab-为什么ismember不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的细胞载体具有不同的&多余的公司名称.以及有趣的公司列表.我试图弄清楚有趣的公司在大型矩阵中的位置.我对所有露面都很感兴趣. 我的代码出于某些原因无法正常工作. ismember始终返回错误.

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

错误:

使用单元格/ismember的错误> cellismemberR2012a(第192行)的输入A 类单元格和char类的输入B必须是字符串的单元格数组, 除非一个是字符串.

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.

单元格/ismember中的错误(第56行)

Error in cell/ismember (line 56)

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

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

两个Vector的值都类似:"Nike","Adidas","BMW"等.

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

推荐答案

除非是一个字符串,否则类单元格的输入A和char类的输入B必须是字符串的单元格数组.

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

这意味着单元格中的每个条目都必须是字符串,在这种情况下不是.如果您的单元格数组包含数值,甚至是 empty 矩阵,您都会收到此错误.

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');

这不是:

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

最有可能意外混入您的细胞阵列的可能是空矩阵.在这些情况下,我始终建议使用调试工具(dbstop if error是我们的朋友)来仔细检查发生了什么.您认为变量应该或应该包含的内容以及变量实际上要包含的内容并不总是相同的.

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.

这篇关于Matlab-为什么ismember不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆