How to save data from a GUI edit box to table using push button?

15 Ansichten (letzte 30 Tage)
I am trying to figure out a way to import data from 3 edit boxes using 1 push button to a table. Please help me with that. I want to say thank you in advance!

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 22 Nov. 2015
Dang - use the handles structure that is passed in as the third parameter to the push button callback to get the handles to the three edit text controls. If the table is part of your GUI (i.e. an uitable) then you would again use the handles structure to get the table handle and use that to update the table. For example,
function pushbutton1_Callback(hObject, eventdata, handles)
% get the string data from the three edit controls
str1 = char(get(handles.edit1,'String'));
str2 = char(get(handles.edit2,'String'));
str3 = char(get(handles.edit3,'String'));
% do some work
% update the table
set(handles.uitable1,'Data',data);
where data is an mxn cell array of data that you wish to display within your table.
  3 Kommentare
Geoff Hayes
Geoff Hayes am 24 Nov. 2015
Hi Dang - you will want to update the existing data (within the table) with the new row (or rows) of data. For example, suppose I want to add two random integers to my table whenever I press a push button. I could do something like
function pushbutton1_Callback(hObject, eventdata, handles)
% create the random numbers
x = {randi(42,1,1) randi(42,1,1)};
% get the current table data
data = get(handles.uitable1,'Data');
if isempty(data)
data = x;
else
% append the new row
data = [data ; x];
end
% update the table
set(handles.uitable1,'Data',data);
Dang Khoa Pham
Dang Khoa Pham am 24 Nov. 2015
That works effectively. Thanks a lot :D

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by