speed up the & operation

1 回表示 (過去 30 日間)
Chaoyang Jiang
Chaoyang Jiang 2018 年 4 月 12 日
コメント済み: Walter Roberson 2018 年 4 月 13 日
How to speed up the following code? I did profiling, and this line takes 3267.72s for calling 245913489 times.
a=[1 0 1 1 0 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1];
b=[1 0 1 1 0 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0];
for i=1:1000000
aat=((a(1,1:24)==0)&(b(1,25:48)==1)&(~ismembc(1:24,5:50)))';
end
  5 件のコメント
Chaoyang Jiang
Chaoyang Jiang 2018 年 4 月 13 日
ismembc seems to be faster than ismember, that is why I used this function.
Walter Roberson
Walter Roberson 2018 年 4 月 13 日
for i=1:1000000
part1 = a(1,1:24)==0;
part2 = b(1,25:48)==1;
part3 = ~ismembc(1:24,5:50);
part4 = part1 & part2 & part3;
aat = part4 .';
end
Now when you profile you can see exactly which part of the expression is taking the most time.
We suspect that it is the ismembc() that is taking all of the time and that the & is relatively fast.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by