How to vectorize this ?

1 次查看(过去 30 天)
Alex Kurek
Alex Kurek 2016-5-2
编辑: Stephen23 2016-5-2
It seems I dont understand sth about vectorization.
Aj = zeros(1, jCount); % it is filled in reality, but here I just swoh the size
uj = zeros(K, jCount); % as above
for angle = 1:K
currentUj = uj(angle, :);
beta(angle) = sum(Aj.*currentUj);
end
Can somebody show me how to vectorize this, so I can learn what I do wrong?
Best regards, Alex

采纳的回答

Stephen23
Stephen23 2016-5-2
编辑:Stephen23 2016-5-2
This does that same as your loop:
beta = sum(bsxfun(@times,Aj,uj),2).';

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by