Matlab - compare Cell-Array rows with mixed content
11 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Andrei Bobrov
on 29 Aug 2011
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 Comments
More Answers (1)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!