I need to chose between two images for postprocessing using uibuttongroup. Why is not working?
1 次查看(过去 30 天)
显示 更早的评论
I have two images as Option 1 and Option 2.
How to make it run and user be able to chose among the two images?
Is it correct How I call it?
Img = bg;
I use
bg = uibuttongroup('Visible','off',...
'Position',[0 0 .2 1],...
'SelectionChangeFcn',@Do_plot);
r1 = uicontrol(bg,'Style',...
'radiobutton',...
'String','Option 1',...
'Position',[10 350 100 30],...
'HandleVisibility','off');
r2 = uicontrol(bg,'Style','radiobutton',...
'String','Option 2',...
'Position',[10 250 100 30],...
'HandleVisibility','off');
% Make the uibuttongroup visible after creating child objects.
bg.Visible = 'on';
Img = bg; %% This is the crucial point where the chosen image goes for more postprocessing.
function Do_plot(hObject, event, varargin)
bg = findobj(gcf,sel);
sel = bg.SelectedObject;
if isempty(sel)
return; %no buttons selected
end
sel_string = sel.String;
switch sel_string
case 'Option 1'
bg = double(croppedImage);
case 'Option 2'
bg = double(J);
end
end
0 个评论
回答(1 个)
Walter Roberson
2019-2-3
Img = bg;
would assign Img a copy of the handle to the button group. There is no numeric index or image associated with a button group.
You are trying to use callbacks as if they are functions that return values. The only kinds of callbacks that ever return values are the callbacks that act as position filters, such as a Position Constraint callback for an imroi. Callbacks for uicontrol, uipanel, axes, button groups, plots, surfaces, contour plots, patches: it is impossible for any of those to return a value. Likewise, graphics objects do not return values either. You can ask what the current state of a graphics object is.
Perhaps you need to read How To Share Variables in Callbacks
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!