vectorize a block matrix calculation
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Luis Isaac
am 28 Apr. 2017
Bearbeitet: Matt J
am 28 Apr. 2017
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 Kommentare
Akzeptierte Antwort
Matt J
am 28 Apr. 2017
TP=kron(a(:),xx);
3 Kommentare
Andrei Bobrov
am 28 Apr. 2017
TP = reshape(bsxfun(@plus,xx',reshape(a,1,1,[])),size(x,2),[])'
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu System Composer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!