Adding values to a table using a pushbutton

4 views (last 30 days)
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

Accepted Answer

Geoff Hayes
Geoff Hayes on 7 Nov 2014
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!

More Answers (1)

george
george on 11 Nov 2014
Hi Geoff, please I have encountered a new challenge. I have been able to add a new row to the table data is entered for the fisrt time but my challenge is, I am unable to add the next data to the next empty row. I want the subsequent data to fill the rows created to receive them. Could you please help me with it, thank you
  2 Comments
Geoff Hayes
Geoff Hayes on 11 Nov 2014
George - your question here shouldn't be posed as an answer to your original question as it makes it confusing for others. You should create a new question posting code that you have written, describing the unexpected results and those that you wish to have. That being said, look at the line tableData = [tableData ; ....]; which adds a row to the previous data stored in the table. That line, and the one that follows are used to update the table.
george
george on 15 Nov 2014
Edited: george on 15 Nov 2014
Thank you so much, it worked perfectly

Sign in to comment.

Categories

Find more on Tables in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!