Attempt to reference field of non-structure array error occurs while using next button

16 次查看(过去 30 天)
I have the following Matlab GUI code for pair copmarison of images on pressing next button it should change the image but it gives the error that "Attempt to reference field of non-structure array." The code is following
% --- Executes just before GUI_Personality_Impressions is made visible.
function GUI_Personality_Impressions_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUI_Personality_Impressions (see VARARGIN)
% Choose default command line output for GUI_Personality_Impressions
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI_Personality_Impressions wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
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;
pos1 = round((scrz(3)-fig_hr)/4);
pos2 = round((scrz(4)-fig_vr)/2);
handles.pos1 = pos1;
handles.pos2 = pos2;
% fig_xcoord = (ScreenSize(3) - fig_width)/2;
handles.pos3 = [pos1 pos2 fig_hr fig_vr];
set(handles.axes1,'pos',[handles.pos3]);
axes(handles.axes1);
imshow('1.tif');
% 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('2.tif');
% myui
% % Get default command line output from handles structure
varargout{1} = handles.output;
handles.co = 1.
for i =1:43*2
handles.save_img{i} = imread ([num2str(i),'.tif']);
end
%%Radio button and next button
hBtnGrp = uibuttongroup('Position',[ 0 0 0.1 0.1], 'Units','Normalized');
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','off', 'Position',[(pos1+326+pos1)/2, pos2-70,70 ,50],'Value',0, 'String','A', 'Tag','A')
uicontrol('Style','Radio', 'Parent',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, hBtnGrp}, 'Units', 'pixels', 'Position', [(((pos1+326+pos1)/2)+(posa+326+posa)/2)/2, pos2- 140,70 ,50 ], 'String', 'Next');
function pushbutton1(hObject,handles,hBtnGrp)
global data
switch get(get(hBtnGrp,'SelectedObject'),'Tag')
case 'A', data = 1;
imshow(handles.save_img{handles.co},'Parent',handles.axes1)
handles.co = handles.co + 1;
case 'B', data = 2;
imshow(handles.save_img{co},'Parent',handles.axes2)
handles.co = handles.co + 1;
end

采纳的回答

Walter Roberson
Walter Roberson 2016-3-15
You are not passing handles to your pushbutton1 . You have named the second parameter of that function "handles", but the second parameter of a callback is always the "event" parameter. So your code is looking at the event data that is passed in automatically and is trying to treat it as if it was the handles data structure.
  6 个评论
Muhammad Farhan  Mughal
I have one more question
function pushbutton1(hObject,handles,hBtnGrp)
global data
switch get(get(hBtnGrp,'SelectedObject'),'Tag')
case 'A', data = 1;
imshow(handles.save_img{handles.co},'Parent',handles.axes1)
handles.co = handles.co + 1;
case 'B', data = 2;
imshow(handles.save_img{co},'Parent',handles.axes2)
handles.co = handles.co + 1;
end
if (handles.co == 83)
cla (handles.axes1); cla (handles.axes2);
close all
end
imshow(handles.save_img{handles.arr(handles.co,1)},'Parent',handles.axes1)
imshow(handles.save_img{handles.arr(handles.co,2)},'Parent',handles.axes2)
guidata(GUIfig, handles)
It gives error when i use close all to close GUI "HAX must be a valid axes handle."

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by