is there any way that can speedup the process of following code... A and B are 50000x20 matrices..?
3 views (last 30 days)
Show older comments
Lakshmi Chodavarapu
on 20 Feb 2018
Commented: Lakshmi Chodavarapu
on 20 Feb 2018
indx=1;
for f=1:length(A)
for b=1:length(B)
if (A(f,1:6)==B(b,1:6))&(A(f,7)==B(b,7))
AA(indx,:)=A(f,[1:7 11]);
BB(indx,:)=B(b,1:11);
else
end
end
indx=indx+1;
end
0 Comments
Accepted Answer
Jos (10584)
on 20 Feb 2018
Your looking for corresponding rows in A and B. intersect might help you
[~,ia,ib] = intersect(A(:,1:7), B(:,1:7), 'rows') ;
AA = A(ia,:) ;
BB = B(ib,:) ;
btw, you loop using length. But length only returns the longest of the dimensions. If you want to loop over rows, use size with the dimension argument, as in size(..., 1)
3 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!