How to edit GUI's uitable data from another .m file?

Hi
How to edit or input GUI's uitable data from another .m file?
For example: I create a uitable in GUIDE called 'uitable1'
The *.m file is:
abcd=(1,2,3,4);
I want to input "abcd" into the uitable1 which I created in GUIDE.
PS: I don't want to create a pushbutton to callback. The thing I want is when I run the *.m file, the result will automatically write into uitable1.

Answers (1)

Youmin - first you need to set two properties of your GUI. Using the property inspector for the GUI figure, ensure that the HandleVisibility property is set to on (the default is callback) and then set the Tag to (for example) MyUitableGui. Save the GUI and launch it. You will now be able to access this GUI by its Tag name/property in your m file. For example, suppose you have an m file called updateUitable.m
function updateUitable
hGui = findobj('Tag','MyUitableGui');
if ~isempty(hGui)
handles = guidata(hGui);
if isfield(handles,'uitable1')
set(handles.uitable1,'Data',randi(42,3,5));
end
end
In the above, we use findobj to get the handle to the object (GUI) whose Tag property is set to MyUitableGui. If this handle is non-empty, then we get the handles to all of the controls within that GUI using guidata. If the handles structure has a field named uitable1 (or whatever the name of this table is) then we set its Data property with the data generated by your script (in this example, a 3x5 array of random integers is generated).
Try the above and see what happens!

Asked:

on 12 Jan 2016

Answered:

on 12 Jan 2016

Community Treasure Hunt

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

Start Hunting!