Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 对数值使用ismember_Matlab - Fatal编程技术网

Matlab 对数值使用ismember

Matlab 对数值使用ismember,matlab,Matlab,我有一个4554x1型向量,叫做company_info,ind_vec。我还有另外一个25 x 1的向量,它是称为groups.industy_labels的单元数组类型 groups.Industry_标签包含数字代码列表。 公司信息ind vec包含相同的数字代码 我计划做下面的工作,在这里我使用ismember返回groups.industy_标签中每个数字代码的索引,然后对另一个向量进行求和,该向量与公司信息ind_vec相关联,即另一个4554 x 1向量 [~, index_sub

我有一个4554x1型向量,叫做company_info,ind_vec。我还有另外一个25 x 1的向量,它是称为groups.industy_labels的单元数组类型

groups.Industry_标签包含数字代码列表。 公司信息ind vec包含相同的数字代码

我计划做下面的工作,在这里我使用ismember返回groups.industy_标签中每个数字代码的索引,然后对另一个向量进行求和,该向量与公司信息ind_vec相关联,即另一个4554 x 1向量

[~, index_sub]              = ismember(company_info.ind_vec, groups.industy_labels);
groups.industy_exps(:, 1)   = accumarray(index_sub, pwgt , [], @sum, 0);

然而,Matlab告诉我ismember只接受字符串的单元数组。还有其他方法吗?

实际上,错误消息有点欺骗性,因为您可以使用
ismember
获取数值:

x=[1 3]
y=[1 2]   
ismember(x,y) %This will work
也可以将其用于单元格数组,但仅用于字符串:

x=[{'a'},{'c'}]
y=[{'a'},{'b'}]
ismember(x,y) %This will work

x=[{1},{3}]
y=[{1},{2}]
ismember(x,y) %This will fail
因此,在您的情况下,您希望在2个数值向量上使用它,而不是在1个数值向量和1个单元格数组上使用它:

x=[1,2] %Numeric vector
y=[{1},{2}] %Cell array

y_numeric = [y{:}] %Made into a numeric vector

ismember(x,y_numeric) %This will work

请注意,这假定单元格数组中的每个条目只包含一个数字。

请先尝试将该单元格数组转换为双数组?-<代码>ismember(公司信息索引、cell2mat(集团工业标签))