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

1 回表示 (過去 30 日間)
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

採用された回答

Jos (10584)
Jos (10584) 2018 年 2 月 20 日
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 件のコメント
Jos (10584)
Jos (10584) 2018 年 2 月 20 日
useful additional comments, Guillaume! +1
Lakshmi Chodavarapu
Lakshmi Chodavarapu 2018 年 2 月 20 日
Thanks a lot for valuable suggestions and inputs Guillaume. The code is running really well with intercept Jos. Thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by