how to use vectorized language or any other methods to replace the following code, in order to make the computation faster
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
following are my current code:
if true
% code
tic;
S = size(P,1);
Q2 = -permute(P,[2 3 1]);
for i = 1:S
Q2(i,:,i) = Q2(i,:,i) + 1;
end
Q2 = reshape(Q2,S,[]);
toc
end
P is the transition probability matrix,
if true
% code
P(:,:,1)=[3/4 1/4;3/4 1/4];
P(:,:,2)=[1/4 3/4;1/4 3/4];
end
My problem is that when the dimension of P is larger than 8000*8000*8,the current computation will be very slow.Is there anyone who know how to optimize the current code? Thank you in advance!
0 commentaires
Réponse acceptée
jgg
le 12 Jan 2016
I think this should work. Replace your for loop with:
i = [1:S]
Q2(i,:,i) = Q2(i,:,i) + 1;
This works on the test case you posed, as far as I can tell, so I think it should work on your much bigger data. Let me know!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!