How to make a Gui checkbox work

2 ビュー (過去 30 日間)
Amanda 2022 年 11 月 14 日
コメント済み: Amanda 2022 年 11 月 14 日
I am trying to make my check box for my gui either disp 'showHistory' or 'hideHistory' depending on whether the the box is checked I figured out how to make is so that when the box is checked that it is disp 'showHistory' but I dont know how to do the second part of this question. Here is my script so far:
first_button = uicontrol('style', 'pushbutton');
set(first_button, 'units', 'normalized', 'position', [0.2,0.7, 0.2, 0.2])
set(first_button, 'string', 'turn left')
set(first_button, 'callback', @turnLeft)
second_button = uicontrol('style', 'pushbutton');
set(second_button, 'units', 'normalized', 'position', [0.4, 0.7, 0.2, 0.2])
set(second_button, 'string', 'step')
set(second_button, 'callback', @step)
third_button = uicontrol('style', 'pushbutton');
set(third_button, 'units', 'normalized', 'position', [0.6, 0.7, 0.2, 0.2])
set(third_button, 'string', 'turn right')
set(third_button, 'callback', @turnRight)
fourth_button = uicontrol('style', 'pushbutton');
set(fourth_button, 'units', 'normalized', 'position', [0.2, 0.5, 0.2, 0.2])
set(fourth_button, 'string', 'left')
set(fourth_button, 'callback', @turnLeft)
fifth_button = uicontrol('style', 'pushbutton');
set(fifth_button, 'units', 'normalized', 'position', [0.4, 0.5, 0.2, 0.2])
set(fifth_button, 'string', 'back')
set(fifth_button, 'callback', @step)
sixth_button = uicontrol('style', 'pushbutton');
set(sixth_button, 'units', 'normalized', 'position', [0.6, 0.5, 0.2, 0.2])
set(sixth_button, 'string', 'right')
seventh_button = uicontrol ('Style','checkbox');
set(seventh_button, 'units', 'normalized', 'position', [0.2, 0.3, 0.2, 0.2])
set(seventh_button, 'string', 'History')
set(seventh_button, 'callback', @toggleHistory)
eighth_button = uicontrol ('style', 'edit');
set(eighth_button, 'units', 'normalized', 'position', [0.4, 0.37, 0.2, 0.05])
set(eighth_button, 'string', '2')
ninth_button = uicontrol('style','pushbutton');
set(ninth_button, 'units', 'normalized', 'position', [0.6, 0.3, 0.2, 0.2])
set(ninth_button, 'string', 'Run!')
function toggleHistory(sender, evendata)


cr 2022 年 11 月 14 日
In the toggleHistory callback, use an if condition to check the value of the checkbox.
if sender.Value == 1
disp showHistory
disp hideHistory
  1 件のコメント
Amanda 2022 年 11 月 14 日
Thank you!


その他の回答 (0 件)


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!

Translated by