- 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
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Matt Fig
on 28 May 2011
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
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!