Two matrices A and B. B is subset of A(rowwise).I want to check the indexes for which row of B is there in A and do some operation on those indexes of A. I tried like this, works for small matrices but takes time on my matrix.suggest alternative

1 view (last 30 days)
A=[0 1 2;2 3 4;1 2 3;4 5 6; 9 8 7;3 4 5];
B=[1 2 3;3 4 5;4 5 6 ];
for k=1:length(B)
for j=1:length(A)
if(B(k,:)==A(j,:))
A(j,3)=1; %operation on superset A,changes 3rd column to 1
end
end
end

Answers (1)

dpb
dpb on 6 Jan 2016
A(ismember(A,B,'rows'),:)=1;

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!