Consider a preliminary speed distribution

I did the following

for i = 1:m, index = 0; for j = 1:n, index = index+values(i,j)*2^(j-1); if (j==1) symbol_chip = chip_values(index+1,:); else symbol_chip = [symbol_chip chip_values(index+1,:)]; end end end 

he tells me the following:

symbol_chip may occur inside a loop. Consider the preliminary distribution of speed.

Any ideas?

+6
memory-management matlab
source share
2 answers

Yes. Each time you go, your elseif block resizes symbol_chip , which is expensive. Instead, rewrite the code so that you have (say) symbol_chip = zeros(max_size, 1); before the cycle. Then change the content, but not the size of the symbol_chip .

You need to change your approach a little, but it will be much faster if you do. If you are not annoyed by the current speed, do not change anything!

+10
source share

M-Lint will throw this warning if you have a variable that grows inside the loop without being previously distributed. You can remove this error by first selecting the collection variable.

For example, if you knew that the variable symbol_chip would contain no more than i * j elements, you can pass it using the instruction:

 symbol_chip = zeros(i*j); 

However, for most applications, preallocation will have only a slight effect on algorithm performance. I would only worry about this if you are dealing with very large data sets.

+2
source share

All Articles