problem with loop while

Hello, I have a problem with a loop. I have a data freq_nat(2,2)=2.5 which depends from an other data Jv=9000 I want 1.45<freq_nat(2,2)<1.65 so i did
while freq_nat(2,2)<1.65 & freq_nat(2,2)>1.45
Jv=Jv+1
end
Jv

Respuestas (1)

James Tursa
James Tursa el 15 de Dic. de 2016

0 votos

You never change the value of freq_nat(2,2) inside your while loop, so if the while condition is true at the start of the loop, it will always be true since you never change its value, resulting in an infinite loop. You need to either change freq_nat(2,2) inside your loop or alter your while test condition.

2 comentarios

salim chaibi
salim chaibi el 16 de Dic. de 2016
sorry i didn't understand I change my code to be more esthetic. So while freq_nat(2,2)<1.65 Jv=Jv+1 end Jv
What I have to do please ?
Jan
Jan el 16 de Dic. de 2016
We cannot guess this. It depends on what you want to achieve. What is Jv? Why to aou increase inside the loop? The loop runs infinitely, because freq_nat(2,2) will stay smaller than 1.65 for ever. Incrementing Jv does not change anything in this condition.

La pregunta está cerrada.

Etiquetas

Preguntada:

el 15 de Dic. de 2016

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by