How to save data from a GUI edit box to table using push button?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Geoff Hayes
2015-11-22
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 个评论
Geoff Hayes
2015-11-24
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);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!