speed up the & operation

2 次查看(过去 30 天)
Chaoyang Jiang
Chaoyang Jiang 2018-4-12
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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by