Get Values of uibuttongroup uicontrol checkboxs when i clicked on other uibuttongroup uicontrol pushbutton

4 views (last 30 days)
I want to get the data of the checkbox values when i clicked on the submit button, presently just the callback is executed but not able to get the values of the checkbox -
get(bg1_cb,'Values) will give the cell values
but when inside the call back execution function, i am not able to retreive the values from the checkbox which i need to pass to OutputData varaible. which is the output function.
function OutputData = AlgRun_Test
%% Intial Variables
S1_Alg = {'Test1','Test2','Test3','Test4','Test5','Test6','Test7'};
%% Create Figure and its Properties
Fig_Left = 200;
Fig_Bottom = 100;
Fig_Width = 210;
Fig_Height = 450;
f = figure('units','pixels','position',[Fig_Left,Fig_Bottom,Fig_Width,Fig_Height],...
'toolbar','none','menu','none');
set(f,'Name','User Algorithm Selection');
set(f,'NumberTitle','off');
%% CheckBox Selection
Left_Next = 5;
if true
G1_Left = Left_Next;
G1_Bottom = 95;
G1_Width = 200;
G1_Height = 350;
bg1 = uibuttongroup('Visible','on','units','pixels',...
'Title','Test Selection','Tag','BG1',...
'Position',[G1_Left G1_Bottom G1_Width G1_Height]);
for i = 1:length(S1_Alg)
% Create three radio buttons in the button group
bg1_cb(i) = uicontrol(bg1,'Style','checkbox',...
'String',S1_Alg{i},'Tag',['BG1_CB' num2str(i)],...
'Position',[10 300-(i-1)*30 200 30],...
'HandleVisibility','off');
end
Left_Next = G1_Left+G1_Width+10;
Pre_Width = G1_Left+G1_Width-10;
end
%% User Confirmation
if true
G4_Left = 5;
G4_Bottom = 15;
G4_Width = Pre_Width;
G4_Height = 75;
bg4 = uibuttongroup('Visible','on','units','pixels',...
'Title','Confirm Selection','Tag','BG4',...
'Position',[G4_Left G4_Bottom G4_Width G4_Height],...
'SelectionChangedFcn',@pbselection);
bg4_pb(1) = uicontrol(bg4,'Style','pushbutton',...
'String','Submit','Callback',@submitcb,...
'Position',[(G4_Width/8) 20 50 30],...
'HandleVisibility','off');
bg4_pb(2) = uicontrol(bg4,'Style','pushbutton',...
'String','Cancel',...
'Position',[((G4_Width/2)+G4_Width/8) 20 50 30],...
'HandleVisibility','off');
end
%% Returning the User Selection Data Back
x = 0;
function pbselection(source,eventdata)
disp(['Previous: ' event.OldValue.String]);
disp(['Current: ' event.NewValue.String]);
disp('------------------');
end
function submitcb(source,event) %(hObject, event, handles)
OutputData = 0;
end
end

Answers (1)

Dennis
Dennis on 24 Jun 2019
Edited: Dennis on 24 Jun 2019
You need to pass the handle of your checkboxes to your submitcb to access the values.
First add those handles as additional input to your callback:
bg4_pb(1) = uicontrol(bg4,'Style','pushbutton',...
'String','Submit','Callback',{@submitcb,bg1_cb},... %<-----
'Position',[(G4_Width/8) 20 50 30],...
'HandleVisibility','off');
Then edit your callback:
function submitcb(source,event,cb) %cb are your checkbox handles
for i=1:7
OutputData=cb(i).Value %do something with them
end
end

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!