A way to optimize this piece of code..
이전 댓글 표시
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
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
2017년 10월 1일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!