Closing MATLAB GUI gives error
2 views (last 30 days)
Show older comments
I have the following code which is working very fine and also saving the required file. But after completing MATLAB GUI while executing "Close all" statement it gives the error. " _HAX must be a valid axes handle". The Code is as under
function varargout = FArhan_GUI_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)
% Get default command line output from handles structure
set(handles.axes1,'units','pixels','visible','off');
set(handles.axes2,'units','pixels','visible','off');
set(gcf, 'units','normalized','outerposition',[0 0 10 10]);
scrz=get(0,'ScreenSize');
fig_hr = 326;
fig_vr = 493;
% set(handles.axes1,'units','pixels','visible','off');h
handles.pos1 = round((scrz(3)-fig_hr)/4);
handles.pos2 = round((scrz(4)-fig_vr)/2);
for i =1:43*2
handles.save_img{i} = imread ([num2str(i),'.tif']);
end
handles.pos3 = [handles.pos1 handles.pos2 fig_hr fig_vr];
% pos3 = [pos1 pos2 800 500];
set(handles.axes1,'pos',handles.pos3);
axes(handles.axes1);
% imshow('introduction1.tif') ;%,'Parent',handles.axes1);
set(handles.axes1,'units','pixels');
% set(handles.axes2,'units','pixels','visible','off');
handles.posa = handles.pos1 +1.5* round(fig_hr);
pos4 = [handles.posa handles.pos2 fig_hr fig_vr];
set(handles.axes2,'pos',[pos4]);
% varargout{1} = handles.output;
% uicontrol('Visible','off','Style','Text', 'HandleVisibility','off','Position' ,[handles.pos1, 10,500 ,30],,20);
handles.results = 0;
handles.text1 =uicontrol('Style','Text', 'HandleVisibility','off','Position' ,[handles.pos1, handles.pos2,500 ,300],'Value',0,'String','Two Images will be shown to you with a question select the image according to the question.Enter user number and press Enter to start', 'Tag','text1','FontSize',25);
handles.edit1 = uicontrol('Style','Edit', 'HandleVisibility','off','Position' ,[4*handles.pos1, handles.pos2,100 ,30]);
handles.button1 = uicontrol('Style', 'pushbutton','Callback', {@pushbutton1_Callback, ancestor(hObject, 'figure')} ,'Units','pixels', 'Position', [4*handles.pos1, handles.pos2-60,100 ,30 ], 'String', 'Enter');
varargout{1} = handles.output;
handles.save = 990;
handles.question = 1;
handles.co = 1;
guidata( hObject,handles);
function pushbutton1_Callback (hObject,eventdata,GUIfig)
handles = guidata(GUIfig);
% handles.results = handles.results+1
x = get(handles.edit1,'String');
handles.results = x;
% % guidata( handles);
% save ('results_values.mat','x')
set(handles.text1,'units','pixels','visible','off');
set(handles.edit1,'units','pixels','visible','off');
set(handles.button1,'units','pixels','visible','off');
hBtnGrp = uibuttongroup('Position',[ 0 0 0.1 0.1], 'Units','Normalized','BackgroundColor',[0.5,0.5,0.5]);
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','off','BackgroundColor',[0.5,0.5,0.5], 'Position',[(handles.pos1+326+handles.pos1)/2, handles.pos2-70,70 ,50],'Value',0, 'String','A', 'Tag','A')
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','off','BackgroundColor',[0.5,0.5,0.5],'Position' ,[(handles.posa+326+handles.posa)/2, handles.pos2-70,70 ,50],'Value',0, 'String','B', 'Tag','B')
uicontrol('Style', 'pushbutton','Callback', {@pushbutton1, ancestor(hObject, 'figure'), hBtnGrp}, 'Units', 'pixels', 'Position', [(((handles.pos1+326+handles.pos1)/2)+(handles.posa+326+handles.posa)/2)/2, handles.pos2- 140,70 ,50 ], 'String', 'Next');
handles.arr = [1,2; 16,17; 31,32; 41,42; 6,7 ; 21,22; 26,27; 36,37; 11,12;
2,3; 17,18; 32,33; 42,43; 7,8 ; 22,23; 27,28; 37,38; 12,13;
3,4; 18,19; 33,34; 43,41; 8,9 ; 23,24; 28,29; 38,39; 13,14;
4,5; 19,20; 34,35 ; 9,10; 24,25; 29,30; 39,40; 14,15;
5,1; 20,16; 35,31 ; 10,6; 25,21; 30,26; 40,36; 15,11;
1,3; 16,18; 31,33 ; 6,8 ; 21,23; 26,28; 36,38; 11,13;
2,4; 17,19; 32,34 ; 7,9 ; 22,24; 27,29; 37,39; 12,14;
3,5; 18,20; 33,35 ; 8,10; 23,25; 28,30; 38,40; 13,15;
1,4; 16,19; 31,34 ; 6,9 ; 21,24; 26,29; 36,39; 11,14;
2,5; 17,20; 32,34 ; 7,10; 22,25; 27,28; 37,40; 12,15;
44,45; 59,60; 74,75; 84,85; 49,50; 64,65; 69,70; 79,80; 54,55;
45,46; 60,61; 75,76; 85,86; 50,51; 65,66; 70,71; 80,81; 55,56;
46,47; 61,62; 76,77; 86,84; 51,52; 66,67; 71,72; 81,82; 56,57;
47,48; 62,63; 77,78 ; 52,53; 67,68; 72,73; 82,83; 57,58;
49,44; 64,59; 79,74 ; 54,49; 69,64; 74,69; 84,79; 59,54;
44,46; 59,61; 74,76 ; 49,51; 64,66; 69,71; 79,81; 54,56;
45,47; 60,62; 75,77 ; 50,52; 65,67; 70,72; 80,82; 55,57;
46,48; 61,63; 76,78 ; 51,53; 66,68; 71,73; 81,83; 56,58;
44,47; 64,70; 74,77 ; 49,52; 64,67; 69,72; 79,82; 54,57;
45,48; 65,71; 75,78 ; 50,53; 65,68; 70,73; 80,83; 55,58;
];
size(handles.arr)
% handles.arr (2,1)
% handles.arr (2,2)
c=1;
handles.(['text',num2str(c)])=('Which one is more Sociable');
c = c+1;
handles.(['text',num2str(c)])=('Which one is more Easygoing');
c=c+1;
handles.(['text',num2str(c)])=('Which one is more Cooperative');
c=c+1;
handles.(['text',num2str(c)])=('Which one is more Fussy');
c=c+1;
handles.(['text',num2str(c)])=('Which one is more Relaxed');
c=c+1;
handles.(['text',num2str(c)])=('Which one is more Imaginative');
uicontrol('Style','Text', 'HandleVisibility','off','Position',[(((handles.pos1+326+handles.pos1)/2)+(handles.posa+326+handles.posa)/2)/2-200, handles.pos2-200,400 ,50 ],'BackgroundColor',[0.5,0.5,0.5],'Value',0,'String',handles.text1, 'Tag','text1','FontSize',20)
a = handles.save;
uicontrol('Style','Text', 'HandleVisibility','off','Position',[0, 10,100 ,50],'BackgroundColor',[0.5,0.5,0.5],'Value',0,'String',[num2str(handles.save),'out of 996 images'], 'Tag','text1','FontSize',12)
handles.save_Data = [0 , 0 ,0, 0 ,0 ];
imshow(handles.save_img{handles.co},'Parent',handles.axes1);
imshow(handles.save_img{handles.co+1},'Parent',handles.axes2);
% set(handles.pushbutton1,'visible','off')
% set(handles.pushbutton2,'visible','off')
% set(handles.axes1,'visible','on')
% set(handles.axes2,'visible','on')
% set(pushbutton,'visible','on')
% hBtnGrp.visible = 'on';
guidata(GUIfig, handles)
function pushbutton1(hObject, event, GUIfig, hBtnGrp)
handles = guidata(GUIfig);
global data;
% handles.co = handles.co + 1
switch get(get(hBtnGrp,'SelectedObject'),'Tag');
case 'A', data = 1;
case 'B', data = 2;
end
img_select_1 = 0;
img_select_2 = 0;
if ( data == 1)
img_select_1 = 1;
end
if ( data == 2)
img_select_2 = 1;
end
% handles.arr(handles.save,1)
% handles.arr(handles.save,2)
handles.save_Data(handles.save,1) = handles.arr(handles.co,1);
handles.save_Data(handles.save,2) = handles.arr(handles.co,2);
handles.save_Data(handles.save,3) = handles.question;
handles.save_Data(handles.save,4) = img_select_1;
handles.save_Data(handles.save,5) = img_select_2;
handles.co = handles.co + 1;
if (handles.co > 166)
handles.co = 1;
end
if (handles.save == 166)
handles.question = 2;
end
if (handles.save == 332)
handles.question = 3;
end
if (handles.save == 498)
handles.question = 4;
end
if (handles.save == 664)
handles.question = 5;
end
if (handles.save == 830)
handles.question = 6;
end
% a = handles.save
if (handles.save ==996)
save_Data = handles.save_Data;
save(['results',num2str(handles.results),'.mat'],'save_Data');
close all
end
% handles.question = handles.question + 1;
handles.save = handles.save + 1;
handles.question = handles.question + 1;
if handles.question > 6
handles.question = 1;
end
my_str = handles.(['text',num2str(handles.question)]);
uicontrol('Style','Text', 'HandleVisibility','off','Position' ,[(((handles.pos1+326+handles.pos1)/2)+(handles.posa+326+handles.posa)/2)/2-200, handles.pos2-200,400 ,50 ],'BackgroundColor',[0.5,0.5,0.5],'Value',0,'String',my_str, 'Tag','text1','FontSize',20)
uicontrol('Style','Text', 'HandleVisibility','off','Position',[0, 10,100 ,50],'BackgroundColor',[0.5,0.5,0.5],'Value',0,'String',[num2str(handles.save),'out of 996 images'], 'Tag','text1','FontSize',12)
imshow(handles.save_img{handles.arr(handles.save,1)},'Parent',handles.axes1)
imshow(handles.save_img{handles.arr(handles.save,2)},'Parent',handles.axes2)
guidata(GUIfig, handles)
10 Comments
Walter Roberson
on 21 Mar 2016
Perhaps the OutputFcn is triggered when the GUI is being shut down in order to determine the value to return to the caller. If the OutputFcn then attempted to use graphics items that no longer existed, it would run into problems. OutputFcn are not intended to be the place the GUI is managed.
Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks 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!