Adding values to a table using a pushbutton

조회 수: 6 (최근 30일)
george
george 2014년 11월 7일
편집: george 2014년 11월 15일
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

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 11월 7일
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!
  댓글 수: 2
george
george 2014년 11월 10일
Hi Geoff,Thank you so much. Its working now
Geoff Hayes
Geoff Hayes 2014년 11월 11일
Glad that I was able to help!

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

추가 답변 (1개)

george
george 2014년 11월 11일
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
Geoff Hayes
Geoff Hayes 2014년 11월 11일
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 2014년 11월 15일
편집: george 2014년 11월 15일
Thank you so much, it worked perfectly

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

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by