PDA

查看完整版本 : GUI 参数调用问题


梅梅
2008-05-10, 17:58
大侠们帮忙看看,哪里有问题......
function boundsedit_Callback(hObject, eventdata, handles)
% hObject handle to boundsedit (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 boundsedit as text
% str2double(get(hObject,'String')) returns contents of boundsedit as a double
global bounds1;
bounds1 = str2double(get(hObject,'string'));
if isnan(bounds1)
errordlg('You must enter a numeric value','Bad Input','modal')
end
........

function boundsedit2_Callback(hObject, eventdata, handles)
% hObject handle to boundsedit2 (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 boundsedit2 as text
% str2double(get(hObject,'String')) returns contents of boundsedit2 as a double
global bounds2;
bounds2 = str2double(get(hObject,'string'));
if isnan(bounds2)
errordlg('You must enter a numeric value','Bad Input','modal')
end

............
function OKpushbutton_Callback(hObject, eventdata, handles)
% hObject handle to OKpushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global bounds;
bounds = [];
bounds = [bounds1,bounds2];
disp(bounds);
......
运行结果::??? Undefined function or variable 'bounds1'.

Error in ==> GA_user>OKpushbutton_Callback at 328
bounds = [bounds1,bounds2];

Error in ==> gui_mainfcn at 75
feval(varargin{:});

Error in ==> GA_user at 44
gui_mainfcn(gui_State, varargin{:});

??? Error while evaluating uicontrol Callback.
这是为什么啊?已经申明了global,怎么还是不能访问到bounds1,bounds2 阿??/

hualiangzi
2008-05-10, 23:47
我和你的问题差不多,只要你要调用某个全局变量,你就必须用global在之前在短衣一次,即调用变量时,还要定义一下。不知我说明白没?

梅梅
2008-05-11, 11:30
明白了,后来解决了,这样真麻烦.........
还是谢谢你哈........

jackcgz
2008-05-14, 10:06
hao o:biggrin:

vvvxyz1
2009-04-11, 09:56
我和你的问题差不多,只要你要调用某个全局变量,你就必须用global在之前在短衣一次,即调用变量时,还要定义一下。不知我说明白没?

非常感谢!我的问题也解决了!