流量不计算,不显示在消息框中



当我运行以下脚本时,Octave只在消息框中计算并显示速度。

total=0
choice=menu(' Welcome to Group 8 Open Channel Hydraulic Calculator click continue to start',' continue');
a=menu(' Please choose unit system', 'SI Units','U.S. Customary Units');
if a==1
choice= menu ('Please choose shape of the channel', 'Rectangle', 'Triangle','Trapezoid');
if (choice==1)
prompt= {'channel top width,b (meter)',' Channel depth,y(meter)','Channel height,h(meter)','Channel length,L(meter)', 'Mannings coefficient,n'};
dlg_title='Please insert channel dimension'
num_lines=1;
answer= inputdlg(prompt, dlg_title,num_lines);
top_width=str2double(answer{1});
channel_depth= str2double(answer{2});
channel_height=str2double(answer{3});
channel_length=str2double(answer{4});
n=str2double(answer{5});
Area= top_width*channel_depth;
Wetted_Perimeter= top_width+2*channel_depth;
Hydraulic_Radius= Area/Wetted_Perimeter;
K=1.00;
Slope= channel_height/channel_length;
b=menu('Please choose formula', 'Chezy Formula', 'Mannings Formula');
if(b==1)
velocity= (1/n)*Hydraulic_Radius^(1/6)*sqrt(Hydraulic_Radius*Slope);
elseif (b==2)
velocity=(K/n)*(Hydraulic_Radius)^(2/3)*sqrt(Slope);
endif
flow_rate= velocity*Area;

elseif (choice==2)
prompt= {'pitch,z (meter)',' Channel depth,y(meter)','Channel height,h(meter)','Channel length,L(meter)', 'Mannings coefficient'};
dlg_title='Please insert channel dimension'
num_lines=1;
answer= inputdlg(prompt, dlg_title,num_lines);
pitch=str2double(answer{1});
channel_depth= str2double(answer{2});
channel_height=str2double(answer{3});
channel_length=str2double(answer{4});
n=str2double(answer{5});
Area= pitch*(channel_depth^2);
Wetted_Perimeter= 2*channel_depth*((1+pitch^2)^(1/2));
Hydraulic_Radius= Area/Wetted_Perimeter;
K=1.00;
Slope= channel_height/channel_length;
b=menu('Please choose formula', 'Chezy Formula', 'Mannings Formula');
if(b==1)
velocity= (1/n)*Hydraulic_Radius^(1/6)*sqrt(Hydraulic_Radius*Slope);
elseif (b==2)
velocity=(K/n)*(Hydraulic_Radius)^(2/3)*sqrt(Slope);
endif
flow_rate= velocity*Area;
elseif(choice==3)
prompt= {'pitch,z (meter)','Bottom width,b(meter)', 'Channel depth,y(meter)','Channel height,h(meter)','Channel length,L(meter)', 'Mannings coefficient'};
dlg_title='Please insert channel dimension'
num_lines=1;
answer= inputdlg(prompt, dlg_title,num_lines);
pitch=str2double(answer{1});
bottom_width=str2double(answer{2});
channel_depth= str2double(answer{3});
channel_height=str2double(answer{4});
channel_length=str2double(answer{5});
n=str2double(answer{6});
Area= (bottom_width+pitch*(channel_depth))*channel_depth;
Wetted_Perimeter= bottom_width+2*channel_depth*((1+pitch^2)^(1/2));
Hydraulic_Radius= Area/Wetted_Perimeter;
K=1.00;
Slope= channel_height/channel_length;
b=menu('Please choose formula', 'Chezy Formula', 'Mannings Formula');
if(b==1)
velocity= (1/n)*sqrt(Hydraulic_Radius*Slope);
elseif (b==2)
velocity=(K/n)*(Hydraulic_Radius)^(2/3)*sqrt(Slope);
endif
flow_rate= velocity*Area;
endif
else a==2
choice= menu ('Please choose shape of the channel', 'Rectangle', 'Triangle','Trapezoid');
if (choice==1)
prompt= {'channel top width,b (ft)',' Channel depth,y(ft)','Channel height,h(ft)','Channel length,L(ft)', 'Mannings coefficient,n'};
dlg_title='Please insert channel dimension'
num_lines=1;
answer= inputdlg(prompt, dlg_title,num_lines);
top_width=str2double(answer{1});
channel_depth= str2double(answer{2});
channel_height=str2double(answer{3});
channel_length=str2double(answer{4});
n=str2double(answer{5});
Area= top_width*channel_depth;
Wetted_Perimeter= top_width+2*channel_depth;
Hydraulic_Radius= Area/Wetted_Perimeter;
K=1.49;
Slope= channel_height/channel_length;
b=menu('Please choose formula', 'Chezy Formula', 'Mannings Formula');
if(b==1)
velocity= (1/n)*Hydraulic_Radius^(1/6)*sqrt(Hydraulic_Radius*Slope);
elseif (b==2)
velocity=(K/n)*(Hydraulic_Radius)^(2/3)*sqrt(Slope);
endif
flow_rate= velocity*Area;

elseif (choice==2)
prompt= {'pitch,z (meter)',' Channel depth,y(meter)','Channel height,h(meter)','Channel length,L(meter)', 'Mannings coefficient'};
dlg_title='Please insert channel dimension'
num_lines=1;
answer= inputdlg(prompt, dlg_title,num_lines);
pitch=str2double(answer{1});
channel_depth= str2double(answer{2});
channel_height=str2double(answer{3});
channel_length=str2double(answer{4});
n=str2double(answer{5});
Area= pitch*(channel_depth^2);
Wetted_Perimeter= 2*channel_depth*((1+pitch^2)^(1/2));
Hydraulic_Radius= Area/Wetted_Perimeter;
K=1.49;
Slope= channel_height/channel_length;
b=menu('Please choose formula', 'Chezy Formula', 'Mannings Formula');
if(b==1)
velocity= (1/n)*Hydraulic_Radius^(1/6)*sqrt(Hydraulic_Radius*Slope);
elseif (b==2)
velocity=(K/n)*(Hydraulic_Radius)^(2/3)*sqrt(Slope);
endif
flow_rate= velocity*Area;
elseif(choice==3)
prompt= {'pitch,z (meter)','Bottom width,b(meter)', 'Channel depth,y(meter)','Channel height,h(meter)','Channel length,L(meter)', 'Mannings coefficient'};
dlg_title='Please insert channel dimension'
num_lines=1;
answer= inputdlg(prompt, dlg_title,num_lines);
pitch=str2double(answer{1});
bottom_width=str2double(answer{2});
channel_depth= str2double(answer{3});
channel_height=str2double(answer{4});
channel_length=str2double(answer{5});
n=str2double(answer{6});
Area= (bottom_width+pitch*(channel_depth))*channel_depth;
Wetted_Perimeter= bottom_width+2*channel_depth*((1+pitch^2)^(1/2));
Hydraulic_Radius= Area/Wetted_Perimeter;
K=1.49;
Slope= channel_height/channel_length;
b=menu('Please choose formula', 'Chezy Formula', 'Mannings Formula');
if(b==1)
velocity= (1/n)*sqrt(Hydraulic_Radius*Slope);
elseif (b==2)
velocity=(K/n)*(Hydraulic_Radius)^(2/3)*sqrt(Slope);
endif
flow_rate= velocity*Area;
endif
end
i = msgbox(['velocity =' num2str(velocity)],['flow rate=' num2str(flow_rate)]);

我期望在消息框中计算流速并与流速一起显示,有什么方法可以修复/定位/纠正错误吗?也许流速应该放在endif(?)之前。包含的代码是为a==2切割的。

当我运行脚本时,流量显示在消息框的标题栏中。这是因为您已经将速度和流量作为两个单独的参数传递给msgbox()函数。该框显示的消息必须包含在第一个参数中。如果传递第二个参数,则将其解释为框的标题。因此,您需要将速度和流量组合到一个字符串参数中。最好的方法是将msgbox()函数替换为:

i = msgbox(["velocity = " num2str(velocity) "nflow rate = " num2str(flow_rate)]);

要使流量出现在新行上,我添加了一个换行字符n。只有当字符串在双引号中才会起作用。如果您希望使用单引号字符串,如果您使用Matlab,则可能必须使用单引号字符串,然后将其变为字符数组似乎可以工作:

i = msgbox(['velocity = ' num2str(velocity); 'flow rate = ' num2str(flow_rate)]);

需要用分号分隔两行。或者,您可以将它们显示在同一行:

i = msgbox(['velocity = ' num2str(velocity) ', flow rate = ' num2str(flow_rate)]);

但是这个看起来不太好。

最新更新