MATLAB pause does not seem to work

47 views (last 30 days)
Dong-Kyeong Lee
Dong-Kyeong Lee on 7 Jul 2017
Edited: TADA on 21 Feb 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 Comments
Jan
Jan on 28 Jul 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.

Sign in to comment.

Answers (3)

Jan
Jan on 28 Jul 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 Comments
Dong-Kyeong Lee
Dong-Kyeong Lee on 9 Aug 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

Sign in to comment.


Akhilesh Thakur
Akhilesh Thakur on 27 Jul 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 Comment
Dong-Kyeong Lee
Dong-Kyeong Lee on 27 Jul 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)

Sign in to comment.


TADA
TADA on 21 Feb 2019
Edited: TADA on 21 Feb 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'

Community Treasure Hunt

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

Start Hunting!