MATLAB pause does not seem to work
31 views (last 30 days)
Show older comments
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
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.
Answers (3)
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
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'
0 Comments
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.
See Also
Categories
Find more on Search Path in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!