HELP! I need to plot my values from if statement, and cant figure out how

if H < 1.5 %Pressure drop is less than 1.5 psi
D = (Qc.^0.381)/(19.17*(H./(Cr.*L))^0.206);
elseif H >= 1.5 %Pressure drop is greater than or equal to 1.5 psi
D = (Qc.^0.381)/(18.93*((P1a.^2-P2a.^2).*Y./Cr.*L)^0.206);
end
xx = linspace(0,2*Qc,1000);
fplot
this is the part of the function that does the calculation and I can't figure out how to plot the D vs. xx

6 Comments

If they are the same size, you can use plot. If that is not the case, you will need to describe your variables in more detail.
ok here is all i have, i managed to plot D, but im also supposed to place a marker at the value of D on the plot and i cant do that.
function [D,P2] = SizingGasPipes(Q,P1,L,H,Case,Unit)
%This function computes the pipe size required to keep the pressure drop
%within an acceptable range for a specified capacity (cubic feet per hour
%or BTU per hour) and upstream pressure P1
%Giving error when user supplies an illegal value
if H>P1
clc
disp('Error: Pressure drop cannot be less than downstream pressure')
P2=('Error');
D=('Error');
return
elseif Q<=0
clc
disp('Error: Flow rate cannot equal zero or negative');
P2=('Error');
D=('Error');
elseif P1<=0
clc
disp('Error: Downstream pressure cannot equal zero or negative');
P2=('Error');
D=('Error');
return
elseif L<=0
clc
disp('Error: Length of pipe cannot equal zero or negative');
P2=('Error');
D=('Error');
return
end
%Calculate inlet pressure
P1a = P1 +14.7;
P2a = P1a + H/27.7;
%generate 100 numbers from 0 to Q
switch Case %seperate Natural Gas from Propane values
case 'NG' %Case 1 is Natural Gas
Cr = 0.6094;
Y = 0.9992;
btucfh=1040;
case 'PP' %case 2 is Propane
Cr = 1.2462;
Y = 0.991;
btucfh=2500;
otherwise
disp('Gas type invalid')
end
switch Unit %Deciding the units to convert the Q accordingly
case 'CFH'
xscale=1;
xtext = 'Capacity is in cubic feet per hour';
case 'BTU'
xscale= btucfh/1000;
xtext = 'Capacity is in British Themal Units per hour';
otherwise
disp('Units invalid')
end
%changing Q according to units supplied
Qc=Q/xscale;
%Calculations for the capacity of natural gas or propane piping
D = zeros(1,1000);
xx = linspace(0,2*Qc,1000);
for ii = 1:1000
Qc(ii)=ii+1;
if H < 1.5 %Pressure drop is less than 1.5 psi
D(ii) = (Qc(ii).^0.381)/(19.17*(H./(Cr.*L))^0.206);
elseif H >= 1.5 %Pressure drop is greater than or equal to 1.5 psi
D(ii) = (Qc(ii).^0.381)/(18.93*((P1a.^2-P2a.^2).*Y./Cr.*L)^0.206);
end
end
plot(xx,D)
end
I you want to add a marker at only a single point, it is easier to use hold on and a single point with the appropriate marker at the appropriate position.
I see, my dilemma is that for me to plot it i need a for loop, but to get the correct asnwer (point on plot) I only get it without the for loop, how do I plot the graph and at the same time find the value without the for loop?
Which of the 1000 point do you want to put a marker?

Sign in to comment.

Answers (1)

Hi,
Just a small correction in the code
if H < 1.5 %Pressure drop is less than 1.5 psi
D = (Qc.^0.381)/(19.17*(H./(Cr.*L))^0.206);
else %Pressure drop is greater than or equal to 1.5 psi
D = (Qc.^0.381)/(18.93*((P1a.^2-P2a.^2).*Y./Cr.*L)^0.206);
end
xx = linspace(0,2*Qc,1000);
plot(xx, D)
This is only possible if your xx and D are of same dimention

2 Comments

thank you sir, I have done that but now i cant find the value for D in order to point it on the plot. Can you please help me with that?
Oh! Are all the inputs to calculate the value of D available?

Sign in to comment.

Categories

Products

Release

R2019a

Asked:

on 7 Jun 2019

Commented:

on 10 Jun 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!