MATLAB: Adding values to a table using a pushbutton

table data

Hello, I am worked on a project in school. I have created two GUIs and I have one of them containing a table and a pushbutton which the user will use to edit the values of the table. When the user clicks on the pushbutton, the second GUI is called and it has edit text field to receive the required information from the user. Afterwards the user presses the add pushbutton on the same GUI and the data should be sent to the table. I have been able to use Tag and Guidata to called the handles from the gui with the table and but I do not know how to get the data into the table when the button is clicked. Please help me, Thank you

Best Answer

George - presumably the add pushbutton is on the second GUI and you need to transfer the data from the edit text box(es) from it to the table in the first GUI. Since you state that you have been able to use Tag and Guidata to called the handles from the gui with the table then that suggests that you know how to have your two GUIs communicate with each other (if this is not the case, see http://www.mathworks.com/matlabcentral/answers/146215-pass-data-between-gui-s for an example).
Suppose then that you have the following pushbutton callback in your second GUI
function add_pushbutton(hObject,eventdata,handles)
% use guidata to get the handles of the first GUI (assumes that first GUI tag is Gui1)
hGui1 = findobj('Tag','Gui1');
if ~isempty(hGui1)
handlesGui1 = guidata(hGui1);
% get the data that is already in the table
tableData = get(handlesGui1.uitable1, 'Data');
% get the data from your edit box(es) on GUI 2
% update tableData with new data
tableData = [tableData ; ....];
% update the table in GUI 1
set(handlesGui1,'Data',tableData);
end
Try the above and see what happens!