0

When I run the following script, Octave only calculates and shows velocity in the message box.

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)]);

I expected the flow rate to be calculated and displayed along with the velocity in the message box, are there any ways to repair/locate/correct the mistake? Perhaps the flow rate should be placed before endif(?). The code included is cut for the a==2.

Wolfie
  • 27,562
  • 7
  • 28
  • 55

1 Answers1

2

When I ran your script the flow rate was displayed in the title bar of the message box. This is because you have passed the velocity and the flow rate as two separate arguments to the msgbox() function. The message that the box displays must be contained in the first argument. If a second argument is passed it is interpreted as the title of the box. You therefore need to combine the velocity and flow rate into a single string argument. The best way to do that is to replace your msgbox() function with:

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

To get the flow rate to appear on a new line I have added a newline character \n. This will only work if the string is in double quotes. If you wish to use single-quoted strings, which you may have to if you are using Matlab, then making it into a character array seems to work:

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

This requires a semi-colon to separate the two lines. Alternatively, you could display them on the same line:

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

but this doesn't look as good.

Howard Rudd
  • 901
  • 4
  • 6