Attempt to reference field of non-structure array error occurs while using next button
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muhammad Farhan Mughal
el 15 de Mzo. de 2016
Comentada: Muhammad Farhan Mughal
el 16 de Mzo. de 2016
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
0 comentarios
Respuesta aceptada
Walter Roberson
el 15 de Mzo. de 2016
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!