Filter löschen
Filter löschen

Vectorizing the loop

1 Ansicht (letzte 30 Tage)
Nirmal
Nirmal am 24 Apr. 2012
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 Kommentare
Nirmal
Nirmal am 24 Apr. 2012
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 am 24 Apr. 2012
+1

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 24 Apr. 2012
x = w*bsxfun(@gt,A.',B)

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by