Matlab - compare Cell-Array rows with mixed content
3 次查看(过去 30 天)
显示 更早的评论
Hi, I've searched already a while and I'm quite surprised that I couldn't find a nice and fast solution for this problem: I want to compare two cell-Arrays (per line) containing numbers and strings.
Example:
A = {'lol',2;'xd',2} B = {'lol',2}
shall return a logical array with
[1;0]
Has anyonane an Idea?
0 个评论
采纳的回答
Andrei Bobrov
2011-8-29
A = cellfun(@num2str,A,'un',0);
B = cellfun(@num2str,B,'un',0);
out = arrayfun(@(i1)all(ismember(A(i1,:),B)),(1:size(A,1))')
or
out = all(ismember(A,B),2);
more
out = all([ismember(A(:,1),B(1)),ismember([A{:,2}]',B{2})],2)
more more
out = arrayfun(@(i1)isequal(A(i1,:),B),(1:size(A,1))');
or
out = cellfun(@(x)isequal(x,B),mat2cell(A,ones(size(A,1),1),2));
or use loop
for i1 = size(A,1):-1:1
out(i1,1) = isequal(A(i1,:),B);
end
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!