Seraphena 发表于 2016-6-14 22:43

GUI get(hobject, 'userdata')输入后变量为空

在利用get(hobject, 'userdata')获取edit text控件输入时,得到的输出为[ ],请问具体什么原因?
程序代码如下:
function varargout = a(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',gui_Singleton, ...
                   'gui_OpeningFcn', @a_OpeningFcn, ...
                   'gui_OutputFcn',@a_OutputFcn, ...
                   'gui_LayoutFcn',[] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before a is made visible.
function a_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;

= xlsread('user_information.xls')

if ~iscellstr(raw)
    for i = 1 : numel(raw)
      n(i) = isnumeric(raw{i});
    end
    raw{n} = num2str(raw{n});
end
handles.user = raw(2 : end, 1)'; %获得用户名和密码
handles.code = raw(2 : end, 2)';

guidata(hObject, handles);


% --- Outputs from this function are returned to the command line.
function varargout = a_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;


function login_user_Callback(hObject, eventdata, handles)

function login_user_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function login_code_Callback(hObject, eventdata, handles)

function login_code_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in log.
function log_Callback(hObject, eventdata, handles)
user = get(handles.login_user, 'string')
% set(gcf,'userdata','a')
code =get(handles.login_code, 'userdata')   %%主要问题处
users = handles.user
codes = handles.code
n = find(strcmp(users, {user}));
if length(n) && isequal(codes{n}, code)
    h = msgbox('登陆成功!');
    uiwait(h);
    delete(gcf);
    figure(1)
    set(1, 'name', '系统界面');
else
    errordlg('用户名或密码错误!', '错误提示');
    set(handles.login_code, 'string', '')
    set(hObject, 'userdata', '')
end



输入相应字符并运行后
code =

   []

页: [1]
查看完整版本: GUI get(hobject, 'userdata')输入后变量为空