(1)颜色选择对话框
语法:
c = uisetcolor
c = uisetcolor([r g b])
c = uisetcolor(h)
c = uisetcolor(...,'dialogTitle')
下面分别对其进行演示:
示例1):c = uisetcolor
c=uisetcolor
结果:
c =
1 0 0
示例2):使用c = uisetcolor([r g b]),其中r g b的值在0到1之间
c=uisetcolor([1 0 0])
结果:
c =
1 0 0
示例3):c = uisetcolor(h),使用句柄
h=plot([0:10],'r');%初始颜色是红色
c = uisetcolor(h);
弹出颜色选择器选择颜色后点击确定,所绘制曲线的颜色发生改变:
示例4):使用c = uisetcolor(...,'dialogTitle') ,自定义标题
c=uisetcolor([1 0 0],'我的颜色选择器')
结果:
综合案例:点击按钮弹出颜色选择对话框,选择颜色改变按钮的背景颜色
hf=figure(...
'units','normalized',...%单位归一化
'menu','none',... %不显示菜单
'color','w',...%设置颜色
'position',[0.2 0.2 0.5 0.5]);%显示的位置
%添加按钮
hbutton=uicontrol(...
'style','pushbutton',...%普通的按钮
'callback','c=uisetcolor(''设置背景颜色'');set(hbutton,''backgroundcolor'',c)',...%回调函数,清除坐标轴上的内容
'string','更改颜色',...%按钮上的内容
'units','normalized',...
'position',[0.4 0.4 0.2 0.2]);
结果:
fff