matlabgui输⼊参数,求问怎样在GUI中实现将输⼊参数赋值给
程序变量
想实现⽤户输⼊参数值,之后运⾏程序将计算结果作图输出,如下图:
⽆标题.jpg (14.97 KB, 下载次数: 3)
2015-10-8 13:47 上传
⽅法是采⽤edit text,之后把程序附在button的callback函数中,实现点击button运⾏程序,结果报错如下:
>> test3
错误使⽤ str2num (line 32)
需要或字符数组输⼊。
出错 test3>pushbutton1_Callback (line 125)
q=str2num(str);
出错 gui_mainfcn (line 95)
feval(varargin{:});
出错 test3 (line 42)
gui_mainfcn(gui_State, varargin{:});
出错 @(hObject,eventdata)test3('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
附上button的callback函数:
function pushbutton1_Callback(hObject, eventdata, handles)
str=get(handles.q,'string');
q=str2num(str);
str=get(handles.G,'string');
G=str2num(str);
y=0.6;
L=1.85;
p2=1.0*10^5;
g=9.8;
t0=77;
d=0.01;
Dvl1=147.84*10^-6;
Dvl2=163*10^-6;
Dvg1=5.49*10^-6;
Dvg2=5.41*10^-6;
Pr1=2.338;
Pr2=2.46;
tc1=0.1309;
tc2=0.1367;
cpl1=2077.4;
cpl2=2064;
ml1=791.9;
ml2=807;
mg1=6.815;
mg2=4.621;
r1=193.56*10^3;
r2=197.6*10^3;
z1=8.155*10^-3;
z2=8.85*10^-3;
ts1=80.59;
ts2=77.35;
vl1=1.263*10^-3;
vl2=1.239*10^-3;
% 先按能量守恒计算出起泡点之后的⼲度分布,因此先设置起泡点之后的数组l1=y*L;
l2=L;
lx=linspace(l1,l2,1000);
xl0=zeros(1,1000);
xl0(1)=0;
p_out=p2;
l=linspace(0,L,1000);
xl=zeros(1,1000);
d0=lx(2)-lx(1);
dz=l(2)-l(1);
% 实现压强与⼲度的迭代计算
while (abs((pl(1000)-p_out)/p_out)>0.001)||(m>9) m=m+1;
if m>1
p_out=pl(1000);
D=(p_out-p1)/(p2-p1);
else
D=1;
end
r3=y*D*r2-y*D*r1+r1;
r4=r1+D*(r2-r1);
% 计算⼲度
for k=2:1000
r=k/1000*r4-k/1000*r3+r3;
xl0(k)=xl0(k-1)+4*d0*q/d/r/G;
end
for k=1:1000
if k
xl(k)=0;
else
A=abs(lx-k/1000*L);
[x,index]=sort(A);
B=[index(1) index(2)];
xl(k)=(xl0(B(1))+xl0(B(2)))/2;
end
end
% 计算沿程压降
ul0=G/ml1;
for k=2:1000
C=k/1000*D;
ml3=C*ml2-C*ml1+ml1;
mg3=C*mg2-C*mg1+mg1;
Dvl3=C*Dvl2-C*Dvl1+Dvl1;
% 这⾥⽤martinelli的⽅法计算压降
if xl(k)==0
matlab数组赋值fLO=0.079*(G*d/Dvl3)^-0.25;
dp1=dp1+dz*2*fLO*G^2/d/ml3;
ul=G/ml3;
dp2=G*(ul-ul0);
dp3=dp3+dz*ml3*g;
pl(k)=pl(1)-dp1-dp2-dp3;
continue
end
break
end
% 起泡点后的压降计算⽅法要调整下dp0=dp1+dp2+dp3;
S1=0;
S2=0;
for j=k:1000
C=j/1000*D;
ml3=C*ml2-C*ml1+ml1;
mg3=C*mg2-C*mg1+mg1;
Dvl3=C*Dvl2-C*Dvl1+Dvl1;
Dvg3=C*Dvg2-C*Dvg1+Dvg1;
Y=(ml3/mg3)^0.5*(Dvg3/Dvl3)^0.1; if Y<=9.5
if G<=500
else if (500
B=2400/G;
else
B=55/G^0.5;
end
end
elseif (9.5
if G<=600
B=520/(Y*G^0.5);
else
B=20/Y;
end
else
B=15000/Y^2/G^0.5;
end
Lo=1+(Y^2-1)*((B*xl(j)^0.875*(1-xl(j))^0.875+xl(j)^1.75));
fLO=0.079*(G*d/Dvl3)^-0.25;
S1=S1+Lo*(xl(j)-xl(j-1));
dp1=4*fLO*(l(j)-l(k-1))/d*G^2/2/ml3*S1/xl(j);
a0=ml3*xl(j)/(ml3*xl(j)+mg3*(1-xl(j)));
dp2=G^2*(xl(j)^2/a0/mg3+(1-xl(j))^2/(1-a0)/ml3-1/ml3);
S2=S2+(a0*mg3+(1-a0)*ml3)*(xl(j)-xl(j-1));
dp3=(l(j)-l(k-1))*g*S2/xl(j);
pl(j)=pl(1)-dp0-dp1-dp2-dp3;
end
end
hl=zeros(1,1000);
Data_Bo=zeros(1,1000);
D=(pl(1000)-p1)/(p2-p1);
for k=1:1000
C=l(k)/L*D;
a=(C*tc2-C*tc1+tc1)/(C*cpl2-C*cpl1+cpl1)/(C*ml2-C*ml1+ml1);
b=((C*z2-C*z1+z1)/g/(C*ml2-C*ml1+ml1-C*mg2+C*mg1-mg1))^0.5;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论