MATLAB pause does not seem to work

31 visualizaciones (últimos 30 días)
Dong-Kyeong Lee
Dong-Kyeong Lee el 7 de Jul. de 2017
Editada: TADA el 21 de Feb. de 2019
I am currently using the pause function to see if a file is growing or not.
while 1
file1 = file.bytes
pause (60)
file2 = file.bytes
if file1 == file2
display('File stopped growing')
break
end
end
However, after running it for 1~2 days, MATLAB skips the pause and thinks that the file is not growing anymore. Is there a way to fix this issue?
For example, I get this message:
name: 'xxx.bin'
date: '07-Jul-2017 13:03:14'
bytes: 7.981710180352000e+12
isdir: 0
datenum: 7.368835439120370e+05
name: 'xxx.bin'
date: '07-Jul-2017 13:03:14'
bytes: 7.981710180352000e+12
isdir: 0
datenum: 7.368835439120370e+05
  7 comentarios
Dong-Kyeong Lee
Dong-Kyeong Lee el 28 de Jul. de 2017
In the original post, I posted the MATLAB output. In 60 seconds (pause of 60), the file should have grown (the file grows every millisecond). However, the file has not grown, and the file has been checked at the same time instead of after 1 minute.
(I have checked that the file is continuously growing, so the file not updating after 60 seconds is not the case here.)
I added "clock" before both file.byte, so that clock is run before and after the pause. The clock returned
2017 7 25 12 6 9.6134
2017 7 25 12 7 9.8243
2017 7 25 12 7 9.8243
2017 7 25 12 7 9.8243
Jan
Jan el 28 de Jul. de 2017
No, you did show some output and some code, but the output cannot be created by the shown code:
file1 = file.bytes
pause (60)
file2 = file.bytes
It is not clear why you assume "file.bytes" to have changed here. And this code will not produce the message:
name: 'xxx.bin'
date: '07-Jul-2017 13:03:14'
bytes: 7.981710180352000e+12
isdir: 0
datenum: 7.368835439120370e+05
which seems to be the output of a dir command.
Now you have posted some output from a clock command:
2017 7 25 12 6 9.6134
2017 7 25 12 7 9.8243
2017 7 25 12 7 9.8243
But we have to guess which code creates this output.
I still assume, that there is a bug in your code. You still did not answer the questions for clarifications I've posted 3 week ago: How has "file" been created? How is it updated between the calls?
You wrote "the fact that MATLAB decides not to carry out pause or tic/toc". But it is still not clear, why you assume that this is a fact.

Iniciar sesión para comentar.

Respuestas (3)

Jan
Jan el 28 de Jul. de 2017
Perhaps it is a kind of overflow in a time counter of the pause command. I do not understand, what you did with tic/toc, please post the code if this is important.
I'd suggest to use a timer instead of a pulling loop with pause.
  5 comentarios
Walter Roberson
Walter Roberson el 28 de Jul. de 2017
You need to call dir() again to get the new bytes value.
Dong-Kyeong Lee
Dong-Kyeong Lee el 9 de Ag. de 2017
Even without calling dir again, it seems to update the number of bits. However, by using timer, the issue seems to have been resolved for the time being

Iniciar sesión para comentar.


TADA
TADA el 21 de Feb. de 2019
Editada: TADA el 21 de Feb. de 2019
I just encountered the exact same weird issue...
aparently you can switch pause on and off, and i got some piece of code from somewhere which turned it off without noticing. which broke a few unit tests... wasted half a day debugging my timers before realizing pause didn't do anything :\
pause off
pause(10) % pause doesn't do anything
pause on
pause(10) % pauses for 10 sec
p = pause()
p =
'on'

Akhilesh Thakur
Akhilesh Thakur el 27 de Jul. de 2017
The code you wrote is hard to understand. If your file is growing or changing why there is a pause between file1 and file 2. If it says the file is not growing definitely there must be some external thing working on it. Matlab doc says pause temporarily stops MATLAB® execution and waits for the user to press any key. So look for that. Another thing is oldState = pause(state) returns the current pause setting and sets the pause state as indicated by state, you can use this and always do a printf to check whetehr there is a problem in the file.
  1 comentario
Dong-Kyeong Lee
Dong-Kyeong Lee el 27 de Jul. de 2017
Dear Akhilesh Thakur,
Thank you for your comment.
The reason why I am putting a pause is because if you read the file bytes without pause, it returns the same value. I want to check if it is still recording data by checking the file size difference after a few seconds.
I do not want the pause to wait for a user input, as I want the whole process to be automated and running for an indefinite amount of time.
The current issue right now is not the case of there being a problem in the file. It is the fact that MATLAB decides not to carry out pause or tic/toc and compares the file at the same time, not at a different time. (The biggest issue is that this problem occurs randomly 1~2 times out of 1 week, so it is not predictable)

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by