App Designer: Programmatically toggle between buttons
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I have a toggle button group with 5 buttons (A, B, C, D etc...). I would like to have another "sequence" button which when pressed, changes the toggle button group from button A pressed (value=1) to button B pressed (value=1) and so on. Is there a way to implement this? I know how to explicitly press one toggle button by changing its value to 1. But I would like the "sequence" button to always press the next button. Thank you
Best
0 comentarios
Respuestas (1)
Brian Hannan
el 3 de Ag. de 2017
You can do this using the Buttons, OldValue, and NewValue properties described here. If you have a button group where the last button is named "next", the following callback will allow you to cyclically toggle the other buttons.
This code checks whether the "next" button has been selected. If so, It finds the index of the previously selected button, identifies the next button down, and sets its value to true.
function ButtonGroupSelectionChanged(app, event)
if strcmp(event.NewValue.Text, 'next')
buttonNameCell = {app.ButtonGroup.Buttons(1:end-1).Text};
lastSelectionIx = find(strcmp(buttonNameCell, event.OldValue.Text));
numButtons = numel(app.ButtonGroup.Buttons);
nextButtonIx = mod(lastSelectionIx, numButtons-1) + 1;
isButtonPressedArray = false(1:numButtons);
isButtonPressedArray(nextButtonIx) = true;
for k = 1:numButtons
app.ButtonGroup.Buttons(k).Value = isButtonPressedArray(k);
end
end
end
0 comentarios
Ver también
Categorías
Más información sobre Develop Apps Using App Designer 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!