Matlab - compare Cell-Array rows with mixed content
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Andrei Bobrov
il 29 Ago 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 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Entering Commands in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!