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

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

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

操作步骤如下:

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

matlab APPdesigner系列-常用5-切换按钮组_第1张图片

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

 matlab APPdesigner系列-常用5-切换按钮组_第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

运行效果如图

matlab APPdesigner系列-常用5-切换按钮组_第3张图片 

 

你可能感兴趣的:(matlab,appdesigner,matlab)