Filter löschen
Filter löschen

speed up the & operation

2 Ansichten (letzte 30 Tage)
Chaoyang Jiang
Chaoyang Jiang am 12 Apr. 2018
Kommentiert: Walter Roberson am 13 Apr. 2018
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 Kommentare
Chaoyang Jiang
Chaoyang Jiang am 13 Apr. 2018
ismembc seems to be faster than ismember, that is why I used this function.
Walter Roberson
Walter Roberson am 13 Apr. 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by