How to save data from a GUI edit box to table using push button?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dang Khoa Pham
el 22 de Nov. de 2015
Comentada: Dang Khoa Pham
el 24 de Nov. de 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 comentarios
Respuesta aceptada
Geoff Hayes
el 22 de Nov. de 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 comentarios
Geoff Hayes
el 24 de Nov. de 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);
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!