How can I use more than one function with inputs and outputs in a uicontrol button callback?
Show older comments
I am trying to create an interface to select fruits from a list:

The Select All and Clear Selected buttons are working, but I don't know how to do the Done button. I want the Done button to copy the check boxes value, and then close the figure.
This is my code up to now. The Done button part is the one not working.
function Test
handles.f.Fruits = {'Apple';'Pear';'Blueberry';'Avocado';'Tomato'};
handles.f.Fig = figure('NumberTitle','off','MenuBar','none');
handles.f.Msg1 = uicontrol('Parent',handles.f.Fig,'Style',...
'text','FontSize',14,'HorizontalAlignment','left','String',...
'Select fruits','Units','normalized','Position',...
[0.05 0.87 0.8 0.1]);
handles.f.Tab1 = uitable('Data',[num2cell(true(length(handles.f.Fruits),1)) handles.f.Fruits], ...
'ColumnEditable',[true false],'ColumnName',[],'Units','normalized',...
'Position',[0.05 0.14 0.9 0.78],'FontSize',14);
handles.f.btn1 = uicontrol('Parent',handles.f.Fig,'Style',...
'pushbutton','Units','normalized','Position',[0.1 0.07 0.3 0.06],...
'FontSize',14,'String','Select All','Callback',{@SelectAll,handles});
handles.f.btn2 = uicontrol('Parent',handles.f.Fig,'Style',...
'pushbutton','Units','normalized','Position',[0.6 0.07 0.3 0.06],...
'FontSize',14,'String','Clear Selected','Callback',...
{@ClearSelected,handles});
handles.f.btn3 = uicontrol('Parent',handles.f.Fig,'Style',...
'pushbutton','Units','normalized','Position',[0.35 0.01 0.3 0.06],...
'FontSize',14,'String','Done','Callback','handles = SaveData(handles); delete(gcf)');
waitfor(handles.f.Fig)
% Print fruits
function SelectAll(hObject,EData,handles)
set(handles.f.Tab1 ,'Data',...
[num2cell(true(length(handles.f.Fruits),1)) ...
handles.f.Fruits])
function ClearSelected(hObject,EData,handles)
set(handles.f.Tab1 ,'Data',...
[num2cell(false(length(handles.f.Fruits),1)) ...
handles.f.Fruits])
function handles = SaveData(handles)
handles.f.Chosen = get(handles.f.Tab1, 'Data');
Thank you very much for any help...
Accepted Answer
More Answers (0)
Categories
Find more on App Building 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!