App Designer: Programmatically toggle between buttons
조회 수: 7 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Brian Hannan
2017년 8월 3일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!