Vectorizing the loop
显示 更早的评论
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 个评论
Junaid
2012-4-24
I think it can be done, could you show small examples for A, B, w.
Nirmal
2012-4-24
Walter Roberson
2012-4-24
cumsum(histc(...)) .* w ??
Nirmal
2012-4-24
Sean de Wolski
2012-4-24
+1
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!