vectorize a block matrix calculation
2 次查看(过去 30 天)
显示 更早的评论
Dear;
I want calculate a big matrix composed of blocks, for that I use the following code:
k=length(a); % Long vector
n=size(xx,1); % 2D or 3D matrix always the same
TP=repmat(zeros(size(xx),k,1); % Big matriz composed by blocks
for i=1:k
TP((i-1)*n+1:i*n,:)=a(i)*xx; % Block i of TP matrix
end
Is there any way to vectorize this code and speed up the calculation Many thanks;
0 个评论
采纳的回答
Matt J
2017-4-28
TP=kron(a(:),xx);
3 个评论
Andrei Bobrov
2017-4-28
TP = reshape(bsxfun(@plus,xx',reshape(a,1,1,[])),size(x,2),[])'
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Block Libraries 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!