attempt to reference field of non structure array matlab error

2 views (last 30 days)
I have made a key.gui which is working fine if you run directly. but when i call it from the login.gui which is another one it is showing me the error attempt to reference field of non structure array. help me!! code for login gui
function varargout = login(varargin)
% LOGIN MATLAB code for login.fig
% LOGIN, by itself, creates a new LOGIN or raises the existing
% singleton*.
%
% H = LOGIN returns the handle to a new LOGIN or the handle to
% the existing singleton*.
%
% LOGIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LOGIN.M with the given input arguments.
%
% LOGIN('Property','Value',...) creates a new LOGIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before login_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to login_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help login
% Last Modified by GUIDE v2.5 01-Nov-2014 12:25:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @login_OpeningFcn, ...
'gui_OutputFcn', @login_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before login is made visible.
function login_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 login (see VARARGIN)
% Choose default command line output for login
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes login wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = login_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
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global type;
if strcmp(type,'Admin')==1
gui4fig=open('regadmin.fig');
else
gui1fig=open('Registration.fig');
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
gui2fig=open('pwdrecovery.fig');
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global type;
conn=database('MatDSN','','');
disp(conn);
user=get(handles.edit1,'string');
pwd=get(handles.edit2,'string');
log=strcat(user,pwd);
if strcmp(type,'Student')==1
setdbprefs('DataReturnFormat','cellarray');
query=strcat('select UserId from Stud_Reg_Tbl where UserId =''',user,''' and Pswd = ''',pwd,'''');
curs =fetch(conn,query);
query2=strcat('select Pswd from Stud_Reg_Tbl where UserId =''',user,''' and Pswd = ''',pwd,'''');
curs2 =fetch(conn,query2);
query3=strcat('select FName from Stud_Reg_Tbl where UserId =''',user,''' and Pswd = ''',pwd,'''');
curs3 =fetch(conn,query3);
global nm;
nm=curs3;
disp(nm);
setappdata(0,'evalue',nm);
comp=strcat(curs,curs2);
ab=strcmp(log,comp);
if (ab==1)
msgbox('Sucess');
gui3fig=open('key.fig');
else
msgbox('Invalid Username and Password');
end
else
setdbprefs('DataReturnFormat','cellarray');
query=strcat('select AdminId from Admin_Reg_Tbl where AdminId =''',user,''' and Pswd = ''',pwd,'''');
curs =fetch(conn,query);
query2=strcat('select Pswd from Admin_Reg_Tbl where AdminId =''',user,''' and Pswd = ''',pwd,'''');
curs2 =fetch(conn,query2);
query3=strcat('select FName from Admin_Reg_Tbl where AdminId =''',user,''' and Pswd = ''',pwd,'''');
curs3 =fetch(conn,query3);
global nm;
nm=curs3;
disp(nm);
setappdata(0,'evalue',nm);
comp=strcat(curs,curs2);
ab=strcmp(log,comp);
if (ab==1)
msgbox('Sucess');
else
msgbox('Invalid Username and Password');
end
end
% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uipanel1
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
global type;
global login;
h=guidata(hObject);
ans=get(eventdata.NewValue,'Tag');
if (strcmp(ans,'radiobutton1')==1)
type='Admin';
%disp(gen);
else
type='Student';
%disp(gen);
end
if true
% code
endlogin=type;
disp(login);
setappdata(0,'evalue',login);
code for key gui
function varargout = key(varargin)
% KEY MATLAB code for key.fig
% KEY, by itself, creates a new KEY or raises the existing
% singleton*.
%
% H = KEY returns the handle to a new KEY or the handle to
% the existing singleton*.
%
% KEY('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in KEY.M with the given input arguments.
%
% KEY('Property','Value',...) creates a new KEY or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before key_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to key_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help key
% Last Modified by GUIDE v2.5 17-Oct-2014 11:50:26
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @key_OpeningFcn, ...
'gui_OutputFcn', @key_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before key is made visible.
function key_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 key (see VARARGIN)
% Choose default command line output for key
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes key wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = key_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
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
%set(handles.edit1,'string','abc');
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% global cd;
% disp(cd);
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
% else
% data=get(handles.edit1,'String');
% data{end+1}=cd;
% set(handles.edit1,'string',data);
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function text2_CreateFcn(hObject, eventdata, handles)
% hObject handle to text2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global nm;
conn=database('MatDSN','','');
setdbprefs('DataReturnFormat','cellarray');
nm=getappdata(0,'evalue');
set(handles.text2,'string',nm);
[p,q,r,s]=intialize1();
disp(['The value of (N) is: ' num2str(p)]);
disp(['The public key (e) is: ' num2str(s)]);
disp(['The value of (Phi) is: ' num2str(q)]);
disp(['The private key (d)is: ' num2str(r)]);
puk=strcat(num2str(s),',',num2str(p));
set(handles.edit1,'string',puk);
prk=strcat(num2str(r),',',num2str(p));
set(handles.edit2,'string',prk);
  1 Comment
Jan
Jan on 1 Nov 2014
Without the corresponding FIG files, we cannot run your code. Unfortuantely you did not provide the complete error message and did not mention the line, which causes the problem. So please concentrate on the essential details only. You cannot expect that a reader studies these 360 lines of code carefully, when you do not boil it down substantially.

Sign in to comment.

Answers (1)

Jan
Jan on 1 Nov 2014
The debugger is the prefect tool to identify and solve problems. Type this in the command line
dbstop if error
Now run your program again. Matlab stops, when the error occurres and you can examine the locally used variables.
  1 Comment
Neha
Neha on 7 Nov 2014
Ohh.. Really very sorry.. I am New to the Matlab support and answers. Both of the gui n the photo of error is provided below
<<
<<
>> Error occur every time when I try to set anything in edit box using set command. >>

Sign in to comment.

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!