필터 지우기
필터 지우기

How to Update Data automatically in a UITABLE GUI?

조회 수: 19 (최근 30일)
Davin
Davin 2015년 8월 11일
댓글: Davin 2015년 8월 12일
Hello,
I am not very used to the GUI framework of MATLAB. I have a GUI, a uitable which is linked to a table situated in my workstation in which the data are constantly changing. So I want to know how I can make the data which are shown in the GUI table, dynamic with a timer say a refresh each 10 seconds.
From what I can see, you need to initiate a timer then a callback?
I would really appreciate any help.
Thank you
D.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 11일
Yes, a timer with a callback that fetched the latest information and set() the Data property of the uitable should work.
  댓글 수: 3
Walter Roberson
Walter Roberson 2015년 8월 12일
OpenFcn is as good a place as any when you are using GUIDE. The Callback would be a property you set for the timer object. It would have nothing to do with CellEditCallback. It should call a function that grabs the data from the table on your workspace (I am presuming that is a database access or perhaps an ActiveX call to Excel).
guifig = ancestor(hObject, 'figure');
timerobj = timer(.....);
set(timerobj, 'Callback', @(src,evt) Update_From_Table(src, evt, guifig));
...
function Update_From_Table(hObject, event, guifig)
handles = guidata(guifig);
do something to get the update from the workspace table into newdata
set(handles.uitable1, 'Data', newdata);
Davin
Davin 2015년 8월 12일
Thanks Walter. I am very new to GUI coding, so I am still a bit stuck on that, the objective of the code is to import changing values from a table in the workspace, my code is like this
guidata(hObject, handles)
guifig = ancestor(hObject, 'figure')
timerobj = timer('TimerFcn', 'stat=false; disp(''Lag'')',...
'StartDelay',3);
start(timerobj)
function Callback(obj, event, string_arg)
txt1 = ' event occurred at ';
txt2 = string_arg;
event_type = event.Type;
event_time = datestr(event.Data.time);
msg = [event_type txt1 event_time];
disp(msg)
disp(txt2)
set(timerobj, 'Callback', @(src,evt) Update_From_Table(src, evt, guifig))
function Update_From_Table(hObject, event, guifig)
handles = guidata(guifig)
newdata = evalin('base', 'JadeVine')
set(handles.JadeVineCapitalPortfolio, 'Data', newdata);
But there is an issue on the Set command, it does not recognise the Callback. Normally, when i will be be changing a value in XL, the same value is being changed in my MATLAB workspace, then hopefully refreshed on the GUI.Thats why i need a timer to refresh the table each 3 to 5 seconds... All of this is in the OpenFcn section....
Could you please give some insigts please?
Thanks very much
D

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by