Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Speeding up areas of my code
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I am lookng to speed up the following lines in my code. Both di and tmp are matrices. Below, I have posted the original line and my attempt to speed this up. However, I have actually made this line slower by trying to speed it up, so I have reverted to the original for now:
Original:
for ii=1:nn
ttt=tmp(:,1:ii)'*di(:,ii);
end
New:
for ii=1:nn
rr4=0;
for lk4=1:letg
t1 = PP_AII{lk4};
sr4=tmp(t1,1:ii)'*di(t1,ii);
rr4=rr4+sr4;
end
ttt=rr4+tmp(PP_Agamgam,1:ii)'*di(PP_Agamgam,ii);
end
Here, PP is a structure containing PP.AII and PP.Agamgam. My aim is to compute the product over the individual elements of P, then sum them all together afterwards. However, Matlab does not want me to do this, since (as mentioned) this actually slows down the code.
Does anyone have any suggestions on how to proceed?
6 commentaires
Réponses (1)
Jan
le 19 Juil 2011
Try to use (U)INT16 variables as counters:
i1 = int16;
for ii = i1:int16(nn)
rr4 = 0;
for lk4 = i1:int16(letg)
t1 = PP_AII{lk4};
sr4 = tmp(t1, i1:ii)' * di(t1, ii);
rr4 = rr4 + sr4;
end
ttt = rr4 + tmp(PP_Agamgam, i1:ii)' * di(PP_Agamgam, ii);
end
4 commentaires
Sean de Wolski
le 19 Juil 2011
Do you have the parallel computing toolbox? There doesn't appear to be any reason why you couldn't make that outer look a parfor.
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!