フィルターのクリア

App Designer: Programmatically toggle between buttons

15 ビュー (過去 30 日間)
Yangfan Peng
Yangfan Peng 2017 年 7 月 31 日
回答済み: Brian Hannan 2017 年 8 月 3 日
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

回答 (1 件)

Brian Hannan
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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by