matlab 我试图使一个计算器使用八度菜单功能,但有解析错误的代码,但我不知道如何定位或确定它

gstyhher  于 2022-12-13  发布在  Matlab
关注(0)|答案(1)|浏览(147)
OCH

error: parse error near line 156 of file C:\Users\exonc\OCH.m

  syntax error

八度音一直这样报告
下面是我的脚本

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

  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= 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)*sqrt(Hydraulic_Radius*Slope);
    elseif (b==2)
    velocity=(K/n)*(Hydraulic_Radius)^(2/3)*sqrt(Slope);
  endif
  flow_rate= velocity*Area;

  elseif (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 (ft)',' Channel depth,y(ft)','Channel height,h(ft)','Channel length,L(ft)', '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 (ft)','Bottom width,b(ft)', 'Channel depth,y(ft)','Channel height,h(ft)','Channel length,L(ft)', '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= 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)*sqrt(Hydraulic_Radius*Slope);
    elseif (b==2)
    velocity=(K/n)*(Hydraulic_Radius)^(2/3)*sqrt(Slope);
  endif
  flow_rate= velocity*Area;
endif
end

我希望当我运行脚本时,菜单函数至少工作到“美国习惯单位”计算,但当我运行它时,脚本停止在if a==2(对于美国习惯单位),有什么方法可以解决这个问题,我想我误用了if/endif/elseif函数或菜单函数。

htrmnn0y

htrmnn0y1#

您在velocity=(K/n)*(Hydraulic_Radius)^(2/3)*sqrt(Slope);行之后缺少endif
为了帮助定位此类错误,请使用编辑器中的折叠按钮,这些按钮位于代码的左侧。当单击if对应的折叠按钮时,if-then-else块中的所有代码(但只有代码)都将折叠。如果折叠的代码更多或更少,则说明此块内部存在问题。

相关问题