How can I share data from a uitable into the workspace of a timer function that reruns periodically?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a script that pulls informations, parses it and then displays it in a uit = uitable(figure) with blank rows every other line. While that figure window is open, my intent is to enable a user to look at the data and add information into the extra blank cells that are available (to comment on the data). This script is meant to run periodically; it should save any user input data so that the next uitable is populated with newly parsed data and also the comments in the blank cells that were typed in by the user during the last run.
As of now, I can run the script, see my uitable, type anything into the blank cells then manually hit Run and see that it works as intended. The problem is when I try to use a timer function to execute the script, it doesn't recognize any variables that would be generated from the script. What happens then is the data is parsed and populated, but anything that the user tpyes into the uitable, doesn't get saved.
My code is pretty crude. I have used 'try, catch and continue' as workarounds for varibles that are not yet asigned until the script has executed fully one time. After running once, the figure appears and only then can the user begin typing. Using dataretrieved = get(uit,'data') I redefine the cells to save what was written in: data(2,2) = dataretrived(2,2), data(4,4) = dataretrieved(4,4), and so on....
For now, I have my timer set to 60 seconds and its callback to run('myscriptname.mlx'). No matter what I type into my uitable after initializing the timer, it runs the second time as if it were the first. If I ping it for uit.data, it tells me nothing exists. I hope the solution isn't too complicated and that I did an ok job of explaining the problem... Any help is appreciated.
댓글 수: 0
채택된 답변
Kevin Phung
2019년 3월 29일
편집: Kevin Phung
2019년 3월 29일
sounds like maybe the handle for your uitable is out of the scope of the function. Etiher pass it as an input, or assign a tag to your table and point back to it in your other function. example:
%in the same script where you've created an instance of your table:
uit.Tag = 'myuit'; %or set(uit,'Tag','myuit')
function someotherfunction(varargin)
uit = findobj(gcf,'Tag','myuit') % look for a graphic object with tag 'myuit' in your CURRENt figure (gcf)
uit.Data %look at data from uitable
end
let me know if this helps you out.
edit: you can also use groot in place of gcf, where you will search through all figures
댓글 수: 2
Kevin Phung
2019년 4월 1일
I would try to avoid using any sort of evalin / assignin functions for global variables. it's bad practice and it is cleaner code if you access the data from the uitable via its object handle.
There also exists a UserData property of all graphic objects, where you can store whatever information you'd like.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dialog Boxes에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!