How to quickly fill in a matrix
Afficher commentaires plus anciens
Hi there,
Does anybody have a "fix" on how to make this function go faster? Essentially, I am trying to fill up the matrix Hpsi using the vector phi in a special way.
Thanks in advance, Andy.
T= 1000;
phi=[1:10];
Hpsi = speye(T);
phi=phi';
pl=length(phi);
for i=1:pl
Hpsi = Hpsi + sparse((i+1):T,1:(T-i),phi(i)*ones(1,T-i),T,T);
end
Réponses (1)
Christine Tobler
le 17 Déc 2015
Use spdiags:
spdiags(repmat(phi([end:-1:1 1])', T), -10:0, T, T)
2 commentaires
akkp
le 18 Déc 2015
Christine Tobler
le 18 Déc 2015
Sorry, I forgot an input:
spdiags(repmat(phi([end:-1:1 1])', T, 1), -10:0, T, T)
Catégories
En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!