Borrar filtros
Borrar filtros

Subtraction is not working in while loop

4 visualizaciones (últimos 30 días)
Imtiaz nabi
Imtiaz nabi el 11 de Feb. de 2022
Respondida: Jan el 11 de Feb. de 2022
Hi, I have encountered a very odd and annoying issue, I am writing a code that will update the previous time of a system with the current time and date. Please take a look at the following code. When I run the code, it is taking forever so I tried to debug it and found out that the values are not getting subtracted inside the while loop. It is causing the loop to run forever without stopping and giving the output. Has anybody ever faced such an issue? Is there anybody who can help me?
%Here's the Code
gps_w = 1823;
dt = 225540000;
gps_sow = 226058400+dt;
gps_sow = round(gps_sow*1000.0)/1000.0;
while (gps_sow >= 604800) %% Seconds in one week 60480
gpsw_new = (gps_sow-604800);
gpss_new = gps_w + 1;
end
while (gps_sow < 0.0)
gpsw_new = gps_sow+604800;
gpss_new = gps_w-1;
end
  2 comentarios
AndresVar
AndresVar el 11 de Feb. de 2022
you didn't modify the value of gps_sow in your while loop. So the condition is always true and it will run forever. You need a gps_sow = ???. I don't understand what you are doing exactly but that's one issue.
Imtiaz nabi
Imtiaz nabi el 11 de Feb. de 2022
I am going to update the GPS time (the time at which the signal was recorded) to the current time and date for which I have converted the user time into GPS week no and second of the week.
The first while loop is creating a new variable and storing the subtractions and additions in it so that it don't replace the old values

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 11 de Feb. de 2022
If you do not change the value of the variable used in the condition of the while loop, this loop must run infinitly:
x = rand;
while x < 0.5
% do anything here without changing x
y = 123^2;
end
If this loop is entered, it must run forever.
Maybe you want to use if instead of while?

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by