- 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.
- 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}.
- For %%3, you referenced N.figure, but there was no field with this name in N. You meant N.fh.
ButtonGroup
조회 수: 4 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!