How can I connect different callbacks to each option of a toggle button in app designer?
6 views (last 30 days)
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);
Handbox=[0 0 400 400];
zahl = 1;
video2 = d.snapshot;
%Video RGB to gray
video_grey = rgb2gray(video2);
videoAdj = imadjust(video_grey);
%Video RGB to BW
BW = imbinarize(videoAdj);
BW_inverse = imcomplement(BW);
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);
Handbox_new = insertObjectAnnotation(video2,'rectangle',Handbox,'Handgeste');
Handbox_crop = imcrop(Format,Handbox);
video_new = imresize(Handbox_crop, [227 227]);
if zahl < 1
%and thats the code of my start button
c = webcam("Webcam(X1-HTL)");
[W] = Funk();
Reshma Nerella on 21 Jun 2021
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,
ToggleButton (Button2) with properties:
Position: [11 32 100 22]
Show all properties
You can use the Text value to find out which button is selected.
For more information refer to the Callbacks section of ButtonGroup Properties documentation page.
Hope this helps!