matlab APPdesigner系列-常用5-切换按钮组

切换按钮组,也是通过选择某一按钮,完成相应的功能。

此示例用选择电梯楼层来说明,电梯一共4层,当按到对应楼层时,该楼层按钮显示为红色,其他为灰色。初始默认楼层为3层。

操作步骤如下:

1)将切换按钮组拖拽到画布中,并修改对应的名称,设置3层为默认楼层

2)添加回调函数,选择颜色

 

 在此使用switch语句进行选择,switch用法在上一篇单选按钮组中已介绍,

对调代码中,app.Button_1.BackgroundColor=[1.00,0.00,0.00];

BackgroundColor是背景颜色,[1.00,0.00,0.00]是三原色的比值;该值直接从背景颜色框中选好颜色后,直接复制其比值;

[1.00,0.00,0.00]为红色,[0.96,0.96,0.96]为浅灰色

            selectedButton = app.ButtonGroup.SelectedObject;
            switch selectedButton.Text
                case '1层'
                    app.Button_1.BackgroundColor=[1.00,0.00,0.00];
                    app.Button_2.BackgroundColor=[0.96,0.96,0.96];
                    app.Button_3.BackgroundColor=[0.96,0.96,0.96];
                    app.Button_4.BackgroundColor=[0.96,0.96,0.96];
                case '2层'
                    app.Button_1.BackgroundColor=[0.96,0.96,0.96];
                    app.Button_2.BackgroundColor=[1.00,0.00,0.00];
                    app.Button_3.BackgroundColor=[0.96,0.96,0.96];
                    app.Button_4.BackgroundColor=[0.96,0.96,0.96];
                case '3层'
                    app.Button_1.BackgroundColor=[0.96,0.96,0.96];
                    app.Button_2.BackgroundColor=[0.96,0.96,0.96];
                    app.Button_3.BackgroundColor=[1.00,0.00,0.00];
                    app.Button_4.BackgroundColor=[0.96,0.96,0.96];
                case '4层'
                    app.Button_1.BackgroundColor=[0.96,0.96,0.96];
                    app.Button_2.BackgroundColor=[0.96,0.96,0.96];
                    app.Button_3.BackgroundColor=[0.96,0.96,0.96];
                    app.Button_4.BackgroundColor=[1.00,0.00,0.00];
            end

运行效果如图

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值