how to check if two elements are in a row of a matrix?
Mostrar comentarios más antiguos
suppose
A=[1 2;
4 5;
6 9]
B=[1 3 5 6;
1 2 4 7;
5 6 4 8;
1 2 3 4].
In this case 1,2 of 1st row of A are present in 2nd row B, similarly all rows of A have to check with rows of B, and create a matrix   C=[6 9]   which are not present in any row of B.
Respuesta aceptada
Más respuestas (2)
Azzi Abdelmalek
el 2 de Jul. de 2015
Editada: Azzi Abdelmalek
el 2 de Jul. de 2015
A=[1 2;
4 5;
6 9
1 8]
B=[1 3 5 6;
1 2 4 7;
5 6 4 8;
1 2 3 4]
out=[];
for ii=1:size(A,1)
for jj=1:size(B,1)
id=all(ismember(A(ii,:),B(jj,:)));
if id==1
out(end+1,:)=A(ii,:);
break
end
end
end
out=setdiff(A,out,'rows')
Andrei Bobrov
el 2 de Jul. de 2015
ii = fullfact([size(A,1),size(B,1)]);
t = arrayfun(@(i1)sum(ismember(B(ii(i1,2),:),A(ii(i1,1),:))),(1:size(ii,1))') < 2;
C = A(accumarray(ii(:,1),t) == 4,:);
Categorías
Más información sobre Function Creation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!