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)
Show older comments
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
1 Comment
Stephen23
on 6 Jan 2016
Learn to write vectorized code, as per dpb's answer, and you will find MATLAB code can be quite fast.
Answers (1)
See Also
Categories
Find more on Logical 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!