Error to applying ismember for cell arrays
1 次查看(过去 30 天)
显示 更早的评论
I really thanks in advance any help. I am trying to use the below command to find any variable from the A member of the B, but encountering with the error. Welcome any suggestion.
[~,JINDX] = cellfun(@(x)(ismember(B,x)),A,'Uni',false);
Error using cell/ismember (line 34)
Input A of class cell and input B of class char must be cell arrays of strings, unless one is a string.
Error in @(x)(ismember(B,x))
34 error(message('MATLAB:ISMEMBER:InputClass',class(a),class(b)));
1 个评论
Stephen23
2020-2-18
编辑:Stephen23
2020-2-18
It is not clear what you expect. Cell array A contains Rx1 character arrays,e.g.:
>> A{1}
ans =
6
9
0
0
8
0
5
while cell array B contains scalar numerics (which would be much better store in once numeric array):
>> B{1}
ans = 6900805
Do you expect that Rx1 character vector to be equivalent to that numeric scalar? For example:
>> Anum = str2double(cellfun(@(v)v(:).',A,'uni',0));
>> Bnum = [B{:}];
>> idx = ismember(Bnum,Anum)
idx =
1 0 0 0 0 0 0 0 0 0
采纳的回答
KSSV
2020-2-18
load("example.mat") ;
N = length(A) ;
A1 =zeros(N,1) ;
for i = 1:N
A1(i) = str2num(A{i}') ;
end
B1 = cell2mat(B)' ;
[c,ia] = ismemebr(A1,B1) ;
6 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!