Matrix interference infinity loop

When you put a value to the counter, for example more than 15 and at a number of attempts 10000. the matrix interference in Loop indefinitely What is the reason for this and how can I fix the problem
code
m=15;
klp=0;
for i=1:m
klp=klp+1;
lp(klp)=top;
end
lp(klp)=top interference to infinity loop

Respuestas (1)

Walter Roberson
Walter Roberson el 22 de Dic. de 2012

0 votos

Are you sure it is an infinite loop, and not just very slow? You are not preallocating your output array, so every time you add more information to the array, MATLAB has to allocate a new block of memory just slightly larger, and copy the old array, then delete the old array -- for every iteration.

7 comentarios

yes infinite loop so after 6 or more hours the out of memory appear to my matlab display LP =
Columns 1 through 11
15 8 0 0 0 0 0 0 0 0 0
Columns 12 through 15
0 0 0 0
LP =
Columns 1 through 11
10 11 0 0 0 0 0 0 0 0 0
Columns 12 through 15
0 0 0 0
LP =
Columns 1 through 11
2 1 0 0 0 0 0 0 0 0 0
Columns 12 through 15
and suddenly interference infinite loop like this
Columns 1 through 11
0 0 0 0 0 0 0 0 0 0 0
Columns 12 through 22
0 0 0 0 15 8 2 2 2 2 2
Columns 23 through 33
2 2 2 2 2 2 2 2 2 2 2
Columns 34 through 44
2 2 2 2 2 2 2 2 2 2 2
Columns 45 through 55
1 to 15 number of link of my network(topology) LP saved request for example 15 8 two link connect by one node
mohammed sportman
mohammed sportman el 23 de Dic. de 2012
when the first number of LP = zero the interference infinity loop like second part with 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 8 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 22 2 222..........infint loop
Walter Roberson
Walter Roberson el 23 de Dic. de 2012
You are getting an out of memory error, and then the display starts repeating the same thing over and over again?
You mention something about "number of attempts 10000". I do not see where that is in the code?
mohammed sportman
mohammed sportman el 24 de Dic. de 2012
the code is very large about 400 line and the number of attempts in the main program that is call the function (where the problem) when number of attempts small (about 500 or 1000) the problem dont appear but when using 10000 the problem will appear
Walter Roberson
Walter Roberson el 24 de Dic. de 2012
Does your code have a try/catch in it? If so then it might be catching the out-of-memory error instead of exiting.
Have you revised your code to pre-allocate the memory yet?
mohammed sportman
mohammed sportman el 24 de Dic. de 2012
no my program code do not have try/catch in it how i can use it? and when i can put them (try / catch) in my program the problem just appear when i use large number of attempts (with same code and same condition) what is deference between large attempts and small(500 and 10000) attempt's in matlab with same program
mohammed sportman
mohammed sportman el 24 de Dic. de 2012
difference(deference)

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Dic. de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by