ButtonGroup

4 ビュー (過去 30 日間)
nsbd
nsbd 2011 年 5 月 28 日
Hi guys.
How can I run it?
"
function [] = test(varargin)
N.fh=figure('units','pixels',...
'position',[500 250 300 400],...
'color',[0.73 0.83 0.96],...
'menubar','none',...
'name','Title',...
'numbertitle','off',...
'resize','off');
N.bg = uibuttongroup('unit','pix',...
'position',[15 25 270 55],...
'title','Back Ground Color',...
'fontsize',9,...
'backgroundcolor',[0.73 0.83 0.96],...
'foregroundcolor',[0.08 0.17 0.55]);
N.blue = uicontrol(N.bg,...
'style','rad',...
'unit','pix',...
'position',[15 15 50 15],...
'string','Blue',...
'value',1,...
'backgroundcolor',[0.73 0.83 0.96]);
N.green = uicontrol(N.bg,...
'style','rad',...
'unit','pix',...
'position',[110 15 50 15],...
'string','Green',...
'value',0,...
'backgroundcolor',[0.73 0.83 0.96]);
N.gray = uicontrol(N.bg,...
'style','rad',...
'unit','pix',...
'position',[200 15 50 15],...
'string','Gray',...
'value',0,...
'backgroundcolor',[0.73 0.83 0.96]);
set(N.bg,{@bg_call,N})
function [] = bg_call(varargin)
N = varargin{3};
switch findobj(get(N.data2,'SelectedObject'))
case N.blue
set(N.figure,'color',[0.73 0.83 0.96]);
case N.green
set(N.figure,'color',[0.6 1 0.6]);
case N.gray
set(N.figure,'color',[0.8 0.8 0.8]);
end
colors will change only with buttongrup.
(don't guide editor, just .m)

採用された回答

Matt Fig
Matt Fig 2011 年 5 月 28 日
The lines I changed are marked with a %%
function [] = test(varargin)
N.fh=figure('units','pixels',...
'position',[500 250 300 400],...
'color',[0.73 0.83 0.96],...
'menubar','none',...
'name','Title',...
'numbertitle','off',...
'resize','off');
N.bg = uibuttongroup('unit','pix',...
'position',[15 25 270 55],...
'title','Back Ground Color',...
'fontsize',9,...
'backgroundcolor',[0.73 0.83 0.96],...
'foregroundcolor',[0.08 0.17 0.55]);
N.blue = uicontrol(N.bg,...
'style','rad',...
'unit','pix',...
'position',[15 15 50 15],...
'string','Blue',...
'value',1,...
'backgroundcolor',[0.73 0.83 0.96]);
N.green = uicontrol(N.bg,...
'style','rad',...
'unit','pix',...
'position',[110 15 50 15],...
'string','Green',...
'value',0,...
'backgroundcolor',[0.73 0.83 0.96]);
N.gray = uicontrol(N.bg,...
'style','rad',...
'unit','pix',...
'position',[200 15 50 15],...
'string','Gray',...
'value',0,...
'backgroundcolor',[0.73 0.83 0.96]);
set([N.blue,N.green,N.gray],'callback',{@bg_call,N}) %%1
function [] = bg_call(varargin)
N = varargin{3};
switch findobj(get(N.bg,'SelectedObject')) %%2
case N.blue
set(N.fh,'color',[0.73 0.83 0.96]); %%3
case N.green
set(N.fh,'color',[0.6 1 0.6]); %%3
case N.gray
set(N.fh,'color',[0.8 0.8 0.8]); %%3
end
  1. For %%1, you forgot the word 'callback' and you were trying to assign the callback to the buttongroup itself, not the buttons. The alternative would be to use the selectionchangefcn of the buttongroup.
  2. For %%2, you used the field data2, but never assigned a field data2. Also, you do not need to use FINDOBJ here, you could replace this with varargin{1}.
  3. For %%3, you referenced N.figure, but there was no field with this name in N. You meant N.fh.
  1 件のコメント
nsbd
nsbd 2011 年 5 月 28 日
ty bro (^_^)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by