MATLAB中GUI的编程问题 100
va=get(handles.edit1,'String');vr=get(handles.edit2,'String');vs=get(handles.edit3,'S...
va=get(handles.edit1,'String');
vr=get(handles.edit2,'String');
vs=get(handles.edit3,'String');
if va<=235.6&&vr>0.7727*va-171.75&&vr<-0.5241*va+133.79
set(handles.text5,'String','干层')
elseif vr<=10.3&&va>(vr+171.75)/0.7727&&va<(21.123-vr)/0.0459
set(handles.text5,'String','水层')
elseif vr>10.3&&va>(133.79-vr)/0.5241&&vr>0.7473*vs+2.8897
set(handles.text5,'String','油层')
elseif va>235.6&&vr<10.3&&vr>-0.0459*va+21.123&&vr>0.7473*vs+2.8897
set(handles.text5,'String','油层')
elseif vr>10.3&&va>(133.79-vr)/0.5241&&vr<0.7473*vs+2.8897
set(handles.text5,'String','水淹层')
elseif vr<10.3&&va>235.6&&vr>-0.0459*va+21.123&&vr<0.7473*vs+2.8897
set(handles.text5,'String','水淹层')
end
guidata(hObject, handles);
我写这段根据三个值判断结果的程序有什么不对的地方吗
试运行后界面提示如下:
Attempt to reference field of non-structure array.
Error in ==> untitled1>pushbutton1_Callback at 171
va=get(handles.edit1,'String');
Error in ==> gui_mainfcn at 75
feval(varargin{:});
Error in ==> untitled1 at 44
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback. 展开
vr=get(handles.edit2,'String');
vs=get(handles.edit3,'String');
if va<=235.6&&vr>0.7727*va-171.75&&vr<-0.5241*va+133.79
set(handles.text5,'String','干层')
elseif vr<=10.3&&va>(vr+171.75)/0.7727&&va<(21.123-vr)/0.0459
set(handles.text5,'String','水层')
elseif vr>10.3&&va>(133.79-vr)/0.5241&&vr>0.7473*vs+2.8897
set(handles.text5,'String','油层')
elseif va>235.6&&vr<10.3&&vr>-0.0459*va+21.123&&vr>0.7473*vs+2.8897
set(handles.text5,'String','油层')
elseif vr>10.3&&va>(133.79-vr)/0.5241&&vr<0.7473*vs+2.8897
set(handles.text5,'String','水淹层')
elseif vr<10.3&&va>235.6&&vr>-0.0459*va+21.123&&vr<0.7473*vs+2.8897
set(handles.text5,'String','水淹层')
end
guidata(hObject, handles);
我写这段根据三个值判断结果的程序有什么不对的地方吗
试运行后界面提示如下:
Attempt to reference field of non-structure array.
Error in ==> untitled1>pushbutton1_Callback at 171
va=get(handles.edit1,'String');
Error in ==> gui_mainfcn at 75
feval(varargin{:});
Error in ==> untitled1 at 44
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback. 展开
展开全部
1、你好,问题就在以下这三行代码:
va=get(handles.edit1,'String');
vr=get(handles.edit2,'String');
vs=get(handles.edit3,'String');
2、注意到,get(handles.edit1,'String');,这就说明你的va、v、vs都是字符串类型的变量,而在后面你拿他与浮点数比较大小了(如,va<=235.6),类型不匹配,这是必须要报错的。
3、修改方法:
va=get(handles.edit1,'String');
vr=get(handles.edit2,'String');
vs=get(handles.edit3,'String');
va=str2num(va);%%将字符串类型数据转化为数字型
vr=str2num(vr);
vs=str2num(vs);
va=get(handles.edit1,'String');
vr=get(handles.edit2,'String');
vs=get(handles.edit3,'String');
2、注意到,get(handles.edit1,'String');,这就说明你的va、v、vs都是字符串类型的变量,而在后面你拿他与浮点数比较大小了(如,va<=235.6),类型不匹配,这是必须要报错的。
3、修改方法:
va=get(handles.edit1,'String');
vr=get(handles.edit2,'String');
vs=get(handles.edit3,'String');
va=str2num(va);%%将字符串类型数据转化为数字型
vr=str2num(vr);
vs=str2num(vs);
更多追问追答
追问
va=str2num(get(handles.edit1,'String'));
vr=str2num(get(handles.edit2,'String'));
vs=str2num(get(handles.edit3,'String'));
我改成这样的了不行啊,我这个是这样的,试运行可以运行出来,直接打开那个fig就算不出来,这是什么原因
追答
嗯,gui是有这个特点,我也遇到过类似的情况,要先打开文件在运行,不能直接双击运行,可能是直接运行这样很多模块没有加载吧,
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询