passing a file to the timer function
显示 更早的评论
Hi, I am having trouble with my program. I am receiving data from 8 channels in one file. At the beginning of the program, I open up the file and parse through it, making an array for each of the channels. Then I plot these values on one graph. Every 100ms the data is updated. I would like for my graph to update as my data is updated. I am using a timer function to try to accomplish this. Everytime the timer function is called, it opens the updated file, parses through the data, makes the 8 arrays for the 8 channels, then updates the graphs and repeats repeats repeats.
The problem I am currently having is that after the first callback of the timer, the command window says "Reference to a cleared variable filetoRead." So obviously the file has been cleared and its trying to read a cleared file. How do I pass the "filetoRead" to the callback function. I tried using UserData but this didnt seem to work. Is there an easier way to refresh the file that i had once previously opened? I have asked this question two times before on the forum and no one answered it for me.
3 个评论
Geoff Hayes
2017-8-2
Patrick - please post some of your code so that we can get an idea of what you have written that leads to the above problem. Are you running this code from within a GUI or as a script? Is data being appended to the file or is the file being overwritten with new data?
Patrick Lydon
2017-8-2
Patrick Lydon
2017-8-3
采纳的回答
更多回答(1 个)
KL
2017-8-3
You need to get the UserData from the timer object inside your timer function.
filetoRead = get(TimerH, 'UserData');
类别
在 帮助中心 和 File Exchange 中查找有关 Scope Variables and Generate Names 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!