How to save data from a GUI edit box to table using push button?
4 views (last 30 days)
Show older comments
Dang Khoa Pham
on 22 Nov 2015
Commented: Dang Khoa Pham
on 24 Nov 2015
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!
0 Comments
Accepted Answer
Geoff Hayes
on 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 Comments
Geoff Hayes
on 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);
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!