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 CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by