MATLAB Answers

Chris
0

How can I share data from a uitable into the workspace of a timer function that reruns periodically?

Chris
さんによって質問されました 2019 年 3 月 29 日
最新アクティビティ Kevin Phung
さんによって コメントされました 2019 年 4 月 1 日
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 件のコメント

サインイン to comment.

1 件の回答

回答者: 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 件のコメント

This deifnitely helped. Additionally, once being able to read from the uitable, hardcoding my variables into the workspace meant I could interact with them: assignin('base','variable',value)
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.

サインイン to comment.



Translated by