Delay in while loop
1 view (last 30 days)
Show older comments
Hi,
I have a script:
While flag
If exist(file)
Read text
...
End
End
I have a folder that create a new file every 2.5/3 seconds , and the idea is that the loop will check if the new file was created and if so continue. Now when running in RT it looks like the while loop is being called only every 5 sec, meaning instead of reading a new file every 3 sec, I get 2 files read every 5 sec.
Do you any idea how to resolve this? Or is it possible to have another matlab function run simultaneously to read the folder for new file and send it via udp and than using fscan in the while?
Many thanks, Yael
7 Comments
Sindar
on 16 Jan 2020
First question: if you don't have data coming in, how often does the while loop cycle? If it's slower than you'd expect, check the run-and-time and see where the delay is.
Does whatever program is generating the files close out quickly? Maybe there's a delay before Matlab can access the data.
Is it possible the delay is related to your filesystem? Maybe it's taking longer to copy than you think. Maybe there's a delay before Matlab sees the files (and using an in-Matlab copy circumvents this). I don't know much that you could do about this, but it's an issue I've heard about before. My only suggestion would be to change out the if exist(~) check. Maybe just try-catch instead. It's possible fopen sees files sooner than exist().
Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements 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!