is there any way that can speedup the process of following code... A and B are 50000x20 matrices..?

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Jos (10584)
Jos (10584) il 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 Commenti
Lakshmi Chodavarapu
Lakshmi Chodavarapu il 20 Feb 2018
Thanks a lot for valuable suggestions and inputs Guillaume. The code is running really well with intercept Jos. Thanks a lot!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices 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!

Translated by