Hello, I am trying to create a GUI that plots data supplied using a function i have in a separate m-file
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
this is what i got so far under the plot button in the GUI
Q = str2num(get(handles.Qbox,'String'));
L = str2num(get(handles.Lbox,'String'));
P1 = str2num(get(handles.P1box,'String'));
H = str2num(get(handles.Qbox,'String'));
global AX;
AX = handles.axes1;
SizingGasPipes(Q,P1,L,H,Case,Unit);
grid on
and here is the rest of my code
function [D,P2,d] = 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
global AX;
axes(AX);
%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 also need to specify on the plot where D is, but im having a hard time finding the answer since its in a for loop
3 comentarios
Walter Roberson
el 8 de Jun. de 2019
xx = linspace(0,2*Qc,1000);
plot(xx,D)
However, D was not calculated on the basis of xx. D was calculated on the basis of qc(ii) which is ii+1
Perhaps Qc(ii) should be xx(ii) instead?
ragheed idrees
el 8 de Jun. de 2019
Walter Roberson
el 8 de Jun. de 2019
What would some sample inputs be for the plot routine?
Respuestas (0)
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!