handle not increment in MATLAB GUI

1 次查看(过去 30 天)
I am writing a MATLAB GUI code for pair comparison where at one step i need to increment handle to reach the next image. Following is the code
function varargout = GUI_Personality_Impressions_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.axes1,'units','pixels');
set(handles.axes2,'units','pixels');
scrz=get(0,'ScreenSize')
% pos2=[(scrz(3)-800)/2 (scrz(4)-600)/2 800 600];
fig_hr = 326;
fig_vr = 493;
handles.co = 0;
pos1 = round((scrz(3)-fig_hr)/4)
pos2 = round((scrz(4)-fig_vr)/2)
% fig_xcoord = (ScreenSize(3) - fig_width)/2;
for i =1:43*2
handles.save_img{i} = imread ([num2str(i),'.tif']);
end
handles.co = handles.co + 1;
pos3 = [pos1 pos2 fig_hr fig_vr];
set(handles.axes1,'pos',[pos3]);
axes(handles.axes1);
imshow(handles.save_img{handles.co},'Parent',handles.axes1);
% pos1 = round((scrz(3)-fig_hr)/ 3)
posa = pos1 +1.5* round(fig_hr);
pos4 = [posa pos2 fig_hr fig_vr]
set(handles.axes2,'pos',[pos4]);
axes(handles.axes2);
imshow(handles.save_img{handles.co + 1},'Parent',handles.axes2);
% imshow('Chinese_eyes+2.tif');
% myui
% % Get default command line output from handles structure
varargout{1} = handles.output;
handles.saveimg{1} = imread('original1.tif');
handles.saveimg{2} = imread('original11.tif');
% imshow(handles.saveimg{1},'Parent',handles.axes1)
% imshow(handles.saveimg{2},'Parent',handles.axes2)
handles.hBtnGrp = uibuttongroup('Position',[ 0 0 0.1 0.1], 'Units','Normalized');
uicontrol('Style','Radio', 'Parent',handles.hBtnGrp, 'HandleVisibility','off', 'Position',[(pos1+326+pos1)/2, pos2-70,70 ,50],'Value',0, 'String','A', 'Tag','A')
uicontrol('Style','Radio', 'Parent',handles.hBtnGrp, 'HandleVisibility','off','Position' ,[(posa+326+posa)/2, pos2-70,70 ,50],'Value',0, 'String','B', 'Tag','B')
% uicontrol('Style', 'pushbutton','Callback', @pushbutton1,'Units', 'pixels','Position', [(((pos1+326+pos1)/2)+(posa+326+posa)/2)/2, pos2- 140,70 ,50 ],'String','Next');
uicontrol('Style', 'pushbutton','Callback', {@pushbutton1, handles}, 'Units', 'pixels', 'Position', [(((pos1+326+pos1)/2)+(posa+326+posa)/2)/2, pos2- 140,70 ,50 ], 'String', 'Next');
handles.co = handles.co + 1;
% handles.hBtnGrp = hBtnGrp;
function pushbutton1(~,~,handles)
global data;
handles.co = handles.co + 1
switch get(get(handles.hBtnGrp,'SelectedObject'),'Tag');
case 'A', data = ;
case 'B', data = 2;
end
% handles.co = handles.co + 1
imshow(handles.save_img{handles.co },'Parent',handles.axes1);
imshow(handles.save_img{handles.co + 1},'Parent',handles.axes2);
Now in the "function pushbutton1(~,~,handles)" handles.co is not increasing more than 2 i.e. once handles.co become 2 even after clicking button it remains to 2.( not increasing to 3,4 and so on )

回答(1 个)

Walter Roberson
Walter Roberson 2016-3-16
At the end of function pushbutton1 add
guidata(handles.hBtnGrp, handles);

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by