Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2008-05-10, 17:58   #1
梅梅
初级会员
 
注册日期: 2008-04-21
年龄: 39
帖子: 4
声望力: 0
梅梅 正向着好的方向发展
默认 GUI 参数调用问题

大侠们帮忙看看,哪里有问题......
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 阿??/
梅梅 当前离线   回复时引用此帖
旧 2008-05-10, 23:47   #2
hualiangzi
初级会员
 
注册日期: 2008-05-02
年龄: 38
帖子: 25
声望力: 18
hualiangzi 正向着好的方向发展
默认 差不多

我和你的问题差不多,只要你要调用某个全局变量,你就必须用global在之前在短衣一次,即调用变量时,还要定义一下。不知我说明白没?
hualiangzi 当前离线   回复时引用此帖
旧 2008-05-11, 11:30   #3
梅梅
初级会员
 
注册日期: 2008-04-21
年龄: 39
帖子: 4
声望力: 0
梅梅 正向着好的方向发展
默认

明白了,后来解决了,这样真麻烦.........
还是谢谢你哈........
梅梅 当前离线   回复时引用此帖
旧 2008-05-14, 10:06   #4
jackcgz
初级会员
 
注册日期: 2008-04-13
年龄: 38
帖子: 24
声望力: 18
jackcgz 正向着好的方向发展
默认

hao o:biggrin:
jackcgz 当前离线   回复时引用此帖
旧 2009-04-11, 09:56   #5
vvvxyz1
初级会员
 
注册日期: 2009-04-09
帖子: 2
声望力: 0
vvvxyz1 正向着好的方向发展
默认 回复: 差不多

引用:
作者: hualiangzi 查看帖子
我和你的问题差不多,只要你要调用某个全局变量,你就必须用global在之前在短衣一次,即调用变量时,还要定义一下。不知我说明白没?
非常感谢!我的问题也解决了!
vvvxyz1 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码


相似的主题
主题 主题作者 版面 回复 最后发表
请问这个方程可以用MATLAB解没有? thb296 MATLAB论坛 6 2008-04-28 19:02
[求助]图像融合方面的知识 peipei MATLAB论坛 2 2008-04-22 21:55
[求助]GAMMA函数 LIKAIYU MATLAB论坛 1 2008-04-21 23:55
[求助]关于Matlab与Java混合编程的环境变量设置 lxduan MATLAB论坛 1 2008-04-03 16:23
【求助】如何做FFT变换? ceeshy MATLAB论坛 1 2007-12-21 11:27


所有时间均为北京时间。现在的时间是 14:13


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.