필터 지우기
필터 지우기

speed up the & operation

조회 수: 2 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by