Answer not updating with changes in variables
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Creating a pressure calculator app using app design.
I have an issue whereby the Reynold's Number is not updating when i change the density units.
Note the Reynold's Number is only calculated when a button is pushed.
During the first run everything works fine however if i decide to change units on the density field then push button again the reynolds number does not change
I added labels to confirm the values for density, velocity and diamter change.
however the reynolds number does not change on line 29, even though the individual values change.
the below code is for the push button
FlowrateUnitsOne = ['m' char(179) '/hr'];
FlowrateUnitsTwo = ['ft' char(179) '/hr'];
FlowrateUnitscheck = app.FlowrateUnits.Value;
app.FlowrateUnits.ValueChangedFcn;
DensityUnits1 = ['kg/m' char(179)];
DensityUnits2 = ['lb/ft' char(179)];
DensityUnit = app.DensityUnits.Value;
if strcmp(DensityUnit,DensityUnits1)
Density = app.DensityofFluidEditField.Value;
elseif strcmp(DensityUnit,DensityUnits2)
Density = 16.0184634 * app.DensityofFluidEditField.Value;
end
if strcmp(FlowrateUnitscheck,FlowrateUnitsTwo)
Flowrate = app.FlowrateofLiquidEditField.Value/(2.2046*3600);
elseif strcmp(FlowrateUnitscheck,FlowrateUnitsOne)
Flowrate = app.FlowrateofLiquidEditField.Value/(3600);
end
if strcmp(app.DiameterUnits.Value,'mm')
Diameter = app.DiameterofPipeEditField.Value/1000;
end
if strcmp(app.DiameterUnits.Value,'inch')
Diameter = app.DiameterofPipeEditField.Value*0.0254;
end
if selectedButton == app.NewtonianButton_2
Area = pi*((Diameter)^2)/4;
Velocity = Flowrate/(Density*Area);
DynamicViscosity = app.ViscosityofFluidEditField.Value;
app.Label.Text = sprintf('%d',Density);
app.Label5.Text = sprintf('%d',Area);
app.Label4.Text = sprintf('%d',Flowrate);
app.Label2.Text = sprintf('%d',Velocity);
app.Label3.Text = sprintf('%d',Diameter);
ReynoldsNumber = (Density*Velocity*Diameter)/(DynamicViscosity);
app.ReynoldsNumberEditField.Value = ReynoldsNumber;
app.Label6.Text = sprintf('%d',ReynoldsNumber);
elseif selectedButton == app.NonNewtonianButton_2
Area = pi*((Diameter)^2)/4;
Velocity = Flowrate/(Density*Area);
ApparentViscosity = app.ViscosityofFluidEditField.Value*(8*Velocity/Diameter)^(app.FlowBehaviourIndexEditField.Value - 1);
ReynoldsNumber = Density*Velocity*Diameter/ApparentViscosity;
app.ReynoldsNumberEditField.Value = ReynoldsNumber;
end
if app.ReynoldsNumberEditField.Value > 4000
app.TypeofFlowLabel.Text = 'Turbulent Flow';
app.TypeofFlowLabel.Visible = 'on';
end
if app.ReynoldsNumberEditField.Value < 2300
app.TypeofFlowLabel.Text = 'Laminar Flow';
app.TypeofFlowLabel.Visible = 'on';
end
if app.ReynoldsNumberEditField.Value > 2300 && app.ReynoldsNumberEditField.Value < 4000
app.TypeofFlowLabel.Text = 'Transient Flow';
app.TypeofFlowLabel.Visible = 'on';
end
end
0 Kommentare
Antworten (1)
Ajay Neeli
am 14 Okt. 2020
Bearbeitet: Ajay Neeli
am 14 Okt. 2020
app.FlowrateUnits.ValueChangedFcn updates the FlowrateUnits. But there is no such function for DensityUnits. Adding app.DensityUnits.ValueChangedFcn might solve the issue.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Function Creation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!