How can I connect different callbacks to each option of a toggle button in app designer?
5 views (last 30 days)
Show older comments
I've written a code for hand gesture recognition, it can detect numbers and letters. Now I want connect the recognition function for letters to one button of a toggle button group in matlab app designer. The function of the number recognition should be selected if I choose on of the toggle button options and the function for the letter recognition should be selected if I press the second option. After that I have a START button which must be pressed to start the chosen program.
But I dont know how to do this as there are no single callback options for each button option. Can someone help me?
% That is the function that should start for the numbers
function [W]= Funk()
d = webcam(2);
load Netzwerk_Zahl;
%handbox settings
Handbox=[0 0 400 400];
zahl = 1;
while zahl(1)
video2 = d.snapshot;
%Video RGB to gray
video_grey = rgb2gray(video2);
videoAdj = imadjust(video_grey);
%Video RGB to BW
BW = imbinarize(videoAdj);
%Inverte Video
BW_inverse = imcomplement(BW);
%Fill holes
BW_IH = imfill(BW_inverse, 'holes');
%change format [x x 1] --> [x x 3] and uint8
BW_3D = cat(3,BW_IH,BW_IH,BW_IH);
Format = im2uint8(BW_3D);
%Create Handbox
Handbox_new = insertObjectAnnotation(video2,'rectangle',Handbox,'Handgeste');
Handbox_crop = imcrop(Format,Handbox);
video_new = imresize(Handbox_crop, [227 227]);
%classify
label=classify(Netzwerk,video_new);
%show
imshow(Handbox_new);
title(char(label));
drawnow;
if zahl < 1
break;
end
end
end
%and thats the code of my start button
c = webcam("Webcam(X1-HTL)");
[W] = Funk();
preview(c);
pause;
0 Comments
Answers (1)
Reshma Nerella
on 21 Jun 2021
Hi,
From my understanding, you want to call different functions based on toggle button selected.
You can use SelectionChangedfcn Callback for ButtonGroup.
selectedButton = app.ButtonGroup.SelectedObject;
It give the information of the selected button. For example,
selectedButton =
ToggleButton (Button2) with properties:
Value: 1
Text: 'Button2'
Icon: ''
Position: [11 32 100 22]
Show all properties
You can use the Text value to find out which button is selected.
Hope this helps!
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps 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!