I want to create a GUI with two sets of radio buttons, one edit and a pushbutton to continue. I cant isolate the two sets of radio buttons into two differente groups so they wont interact with eachother. only one option can be selected at a time each

1 Ansicht (letzte 30 Tage)
This is the code I have now:
function Window
global IdImage Counter_ImageFiles
% Create and then hide the UI as it is being constructed.
f = figure('Visible','off','Position',[360,500,450,500],'NumberTitle','off','ToolBar','none','Resize','off','MenuBar','none','Color',[0.95 0.95 0.95]);
% bg = uibuttongroup('Title','How do you want the images opened?','FontSize',10,'Position',[.1 .77 .8 .19]);
% bg2 = uibuttongroup('Visible','off','Position',[0 0 1 1]);'Visible','off','Position',[0.2 0.01 .7 .8]
FolderLocation1='';
hp = uipanel('Title','How do you want the images opened?','FontSize',10,'Position',[.1 .77 .8 .19]);
hp2 = uipanel('Title','Please select capture area/scope and magnification','FontSize',10,'Position',[.1 .4 .8 .3]);
% Construct the components.
% htext = uicontrol('Style','text','String','How do you want the images opened?','Position',[-77,440,450,35],'FontSize',10);
hRb = uicontrol('Style','radiobutton','String','You pick image one at a time','Value',1,'Position',[60 430 300 20],'FontSize',10);
hRb2 = uicontrol('Style','radiobutton','String','Computer opens images from folder automat','Value',0,'Position',[60 410 300 20],'FontSize',10);
% htext1 = uicontrol('Style','text','String','Please select capture area/scope and magnification','Position',[15,340,350,15],'FontSize',10);
hRb3 = uicontrol('Style','radiobutton','String','PHX - Reichert-Jung 500x - U50 Camera','Value',1,'Position',[60 300 300 20],'FontSize',10);
hRb4 = uicontrol('Style','radiobutton','String','HCMO - Axiovert 500x','Value',0,'Position',[60 280 300 20],'FontSize',10);
hRb5 = uicontrol('Style','radiobutton','String','HCMO - Observer D1 500x','Value',0,'Position',[60 260 300 20],'FontSize',10);
hRb6 = uicontrol('Style','radiobutton','String','Greer - Olympus BX51M 500x','Value',0,'Position',[60 240 300 20],'FontSize',10);
hRb7 = uicontrol('Style','radiobutton','String','METL - 500x','Value',0,'Position',[60 220 300 20],'FontSize',10);
htext2 = uicontrol('Style','text','String','Enter the complete path','Position',[-112,120,450,50],'FontSize',9);
hEdit = uicontrol('Style','edit','String','C:\Users\h146550\Documents\MATLAB','Position',[50 100 355 20],'Callback',@edit_Callback,'FontSize',8);
hOk = uicontrol('Style','pushbutton','String','OK','Position',[125,40,70,25],'Callback',@Okbutton_Callback,'FontSize',9);
hCan = uicontrol('Style','pushbutton','String','Cancel','Position',[245,40,70,25],'Callback',@Canbutton_Callback,'FontSize',9);
% bg.Visible='on';
% bg2.Visible='on';
% Initialize the UI.
% Change units to normalized so components resize automatically.
f.Units = 'normalized';
hOk.Units = 'normalized';
hCan.Units = 'normalized';
% Assign the a name to appear in the window title.
f.Name = 'Select the desired settings';
% Move the window to the center of the screen.
movegui(f,'center')
% Make the window visible.
f.Visible = 'on';
function Okbutton_Callback(source,eventdata)
global AutomaticSelection MicroscopeID gridd conv_factor
AutomaticSelection = get(hRb,'Value');
vals = get(hRb3,'Value');
vals2 = get(hRb4,'Value');
vals3 = get(hRb5,'Value');
vals4 = get(hRb6,'Value');
if vals==1
close; MicroscopeID=1;
gridd=imread('pixelgrid_PHX.bmp'); conv_factor=278000;
elseif vals2==1
close; MicroscopeID=2;
gridd=imread('pixelgrid_HCMOAxio.bmp'); conv_factor=368000;
elseif vals3==1
close; MicroscopeID=3;
gridd=imread('pixelgrid_HCMOobserver.bmp'); conv_factor=190000;
elseif vals4==1
close; MicroscopeID=4;
gridd=imread('pixelgrid_Greer.bmp'); conv_factor=9400;
else
close; MicroscopeID=5;
gridd=imread('pixelgrid_METL.bmp'); conv_factor=151000;
end
FolderLocation = get(hEdit,'string');
FolderLocationcheck = strcmp(FolderLocation,FolderLocation1);
if FolderLocationcheck==1
close all
Window8
else
directoryCheck2 = isdir(FolderLocation);
if directoryCheck2==1
if AutomaticSelection==1
close all;
[filename, pathname] = uigetfile({'*.bmp';'*.jpg';'*.tiff';'*.png'}, 'Please select an image to evaluate...',FolderLocation);
IdImage.ID=fullfile(pathname,filename);
Counter_ImageFiles=1;
Resultval=singleEDM3(IdImage);
else
directoryCheck = isdir(FolderLocation);
close all;
[IdImage,Counter_ImageFiles]=recursiveEDM(FolderLocation);
end
else
close all
Window8
end
end
end
function Canbutton_Callback(source,eventdata)
close all;
clear;
end
function edit_Callback(f,source,eventdata)
set(f,'KeyPressFcn',@displays)% (eventDat.Key));
function displays(fig_obj,eventDat)
if strcmp(eventDat.Key,'return')
Okbutton_Callback
else
% display 'no aplicable'
end
end
end
end
I cant isolate the two sets of radio buttons and letting only one option to be selected at a time on each set, simultaneously. Please help!

Antworten (2)

Rick Rosson
Rick Rosson am 20 Feb. 2016
Please include the button group's handle bg or bg2 as the first argument that you pass to uncontrol function for each radio button, as follows:
hRb3 = uicontrol(bg,'Style','radiobutton', ...

Aaron Verdugo
Aaron Verdugo am 22 Feb. 2016
But if I do that the first set of radiobuttons disappear

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by