How can I share data from a uitable into the workspace of a timer function that reruns periodically?
3 views (last 30 days)
Show older comments
Chris on 29 Mar 2019
Commented: Kevin Phung on 1 Apr 2019
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.
Kevin Phung on 29 Mar 2019
Edited: Kevin Phung on 29 Mar 2019
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')
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
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
Kevin Phung on 1 Apr 2019
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.
More Answers (0)
Find more on Interactive Control and Callbacks 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!