필터 지우기
필터 지우기

Vectorizing the loop

조회 수: 1 (최근 30일)
Nirmal
Nirmal 2012년 4월 24일
This code is similar to the histc function, but each element has weights associated with it. I'm looking to either use an alternate function or to vectorize it to make things faster
I have arrays A and B, and w is an array of weights associated with each element in A.
I'm hoping to calculate:
for i=1:length(B)
x(i) = sum((A>B(i)).*w)
end
Any help is appreciated. Thanks.
  댓글 수: 5
Nirmal
Nirmal 2012년 4월 24일
Not sure if that works - particularly because cumsum(histc(...)) will have the size of B and w will have the size of A.
Sean de Wolski
Sean de Wolski 2012년 4월 24일
+1

댓글을 달려면 로그인하십시오.

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 4월 24일
x = w*bsxfun(@gt,A.',B)
  댓글 수: 1
Nirmal
Nirmal 2012년 4월 24일
Awesome

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by