A way to optimize this piece of code..
Afficher commentaires plus anciens
I have a switch..case inside a nested 'for-loop'. This makes the program very slow, as the for-loops themselves run for a number of iterations. Can someone suggest me a way to optimize this piece of code?
for iter = 1 : 10
for i = 1 : 10
for j = 1 : 5
if (H(j,i) == 1)
tempr = [tempr, newbitvalues(j,i)];
end
end
nZeros = nnz(~tempr);
nOnes = nnz(tempr);
switch recdmsg(i)
case 1
if nZeros > nOnes
recdmsg(i) = ~recdmsg(i);
end
case 0
if nOnes > nZeros
recdmsg(i) = ~recdmsg(i);
end
end
tempr = [];
end
end
2 commentaires
It would be easier if you explained what you are trying to achieve and provided test data/arrays. I assume that the outer loop is for multiplying the run time by 10 for measuring the performance, but in the rest of the code many operations make little sense (to me).
Vijay
le 1 Oct 2017
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements 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!