GUI Work with plotting time v temp

Hello lovely people!
I am attempting to create a code that plots Temperature vs time, the first bit of code on (a) is me doing the math for 50 and 140 temperature. After that is loop where I define the density and viscocity at different temperatures, but it won't do the equation like I wanted to. Any suggestions?
%% GUI #2
volume = 0.0125 % in ft3
D = 0.73/12 % in ft
density = 1.94 % at 50 F
den = 1.91 % at 140 F
vi = 2.73*(10^-5) % for 50 F
visc = 0.974*(10^-5) % for 140 F
Vel50 = (2100*vi)/(density*D) % ans in ft/s % velocity at 50 F
Vel140 = (2100*visc)/(den*D)
t = (4*volume)/(pi*(D^2)*Vel50) % ans in seconds time at 50 F
t140 = (4*volume)/(pi*(D^2)*Vel140) % ans in seconds
% B
Vel5 = (4000*vi)/(density*D) % ans in ft/s
Vel14 = (4000*visc)/(den*D)
t = (4*volume)/(pi*(D^2)*Vel5) % ans in seconds
t140 = (4*volume)/(pi*(D^2)*Vel14) % ans in seconds
% Graph at various water temperatures
dens = [1.940 1.938 1.931 1.908 1.869]; % different densities at temps from chart in book
for k = 1:numel(dens)
if dens == 1.940
vi = 3.732*(10^-5)
disp('Temperature of water is 32 F')
T = 32;
elseif dens == 1.938
vi = 2.344*(10^-5)
disp('Temperature of water is 60 F')
T = 60;
elseif dens == 1.931
vi = 1.5*(10^-5)
disp('Temperature of water is 90 F')
T = 90;
elseif dens == 1.908
vi = 9.743*(10^-6)
disp('Temperature of water is 140 F')
T = 140;
elseif dens == 1.869
vi = 6.342*(10^-6)
disp('Temperature of water is 200 F')
T = 200;
end
Vel(k) = (2100*vi)/(dens*D)
end
for j = 1:numel(Vel)
tk = (4*volume)/(pi*(D^2)*Vel)
end
Tf = [32 60 90 140 200]
plot(Tf,Vel)

Respuestas (2)

VBBV
VBBV el 6 de Dic. de 2020
You can change the for loop structure to below and plot time vs emp
for k = 1:numel(dens)
if dens(k) == 1.940
vi = 3.732*(10^-5)
disp('Temperature of water is 32 F')
T(k) = 32;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
elseif dens(k) == 1.938
vi = 2.344*(10^-5)
disp('Temperature of water is 60 F')
T(k) = 60;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
elseif dens(k) == 1.931
vi = 1.5*(10^-5)
disp('Temperature of water is 90 F')
T(k) = 90;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
elseif dens(k) == 1.908
vi = 9.743*(10^-6)
disp('Temperature of water is 140 F')
T(k) = 140;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
elseif dens(k) == 1.869
vi = 6.342*(10^-6)
disp('Temperature of water is 200 F')
T(k) = 200;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
end
end
plot(T,Vel,'-b',tk,T,'-r.')
legend('Temp vs Vel','Time vs Temp')

15 comentarios

Caution: if you have an array of literal values like
dens = [1.940 1.938 1.931 1.908 1.869]
and if you compare them with == against the same literal values such as 1.940 ... then MATLAB does not guarantee that they will match.
In theory even if you had
if 1.23456 == 1.23456
then MATLAB does not guarantee that they will match.
In practice, they probably will... but for example if one of them had be save'd in a previous release and pulled back into a newer release, then it might not match.
Better is to never use == between floating point numbers that are not certain to derive from the same source. It is valid, for example, to do something like
find(x == max(x))
because max(x) guarantees that it copies bit patterns (except for nan... it does not guarantee to preserve identity of nan.)
When I put that loop into the matlab it worked, but when I did it in the GUI app, it only showed values at T = 32, I attached my modified GUI code below, as well as what the graph is popping up as.
function DiameterinEditFieldValueChanged(app, event)
D = app.DiameterinEditField.Value/12; % Diameter in ft
volume = app.Volumeft3EditField.Value;
% Graph at various water temperatures
dens = [1.940 1.938 1.931 1.908 1.869];
for k = 1:numel(dens)
if dens(k) == 1.940
vi = 3.732*(10^-5)
disp('Temperature of water is 32 F')
T(k) = 32;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
elseif dens(k) == 1.938
vi = 2.344*(10^-5)
disp('Temperature of water is 60 F')
T(k) = 60;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
elseif dens(k) == 1.931
vi = 1.5*(10^-5)
disp('Temperature of water is 90 F')
T(k) = 90;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
elseif dens(k) == 1.908
vi = 9.743*(10^-6)
disp('Temperature of water is 140 F')
T(k) = 140;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
elseif dens(k) == 1.869
vi = 6.342*(10^-6)
disp('Temperature of water is 200 F')
T(k) = 200;
Vel(k) = (2100*vi)/(dens(k)*D)
tk(k) = (4*volume)/(pi*(D^2)*Vel(k))
end
end
for k = 1:numel(dens)
if dens(k) == 1.940
vi = 3.732*(10^-5)
disp('Temperature of water is 32 F')
T(k) = 32;
Velo(k) = (4000*vi)/(dens(k)*D)
tkt(k) = (4*volume)/(pi*(D^2)*Velo(k))
elseif dens(k) == 1.938
vi = 2.344*(10^-5)
disp('Temperature of water is 60 F')
T(k) = 60;
Velo(k) = (4000*vi)/(dens(k)*D)
tkt(k) = (4*volume)/(pi*(D^2)*Velo(k))
elseif dens(k) == 1.931
vi = 1.5*(10^-5)
disp('Temperature of water is 90 F')
T(k) = 90;
Velo(k) = (4000*vi)/(dens(k)*D)
tkt(k) = (4*volume)/(pi*(D^2)*Velo(k))
elseif dens(k) == 1.908
vi = 9.743*(10^-6)
disp('Temperature of water is 140 F')
T(k) = 140;
Velo(k) = (4000*vi)/(dens(k)*D)
tkt(k) = (4*volume)/(pi*(D^2)*Velo(k))
elseif dens(k) == 1.869
vi = 6.342*(10^-6)
disp('Temperature of water is 200 F')
T(k) = 200;
Velo(k) = (4000*vi)/(dens(k)*D)
tkt(k) = (4*volume)/(pi*(D^2)*Velo(k))
end
end
plot(app.UIAxes,tk,T,'-r.',tkt,T,'-b.')
legend(app.UIAxes,'Time vs Temp: Laminar', 'Time vs Temp: Turbulent')
end
VBBV
VBBV el 6 de Dic. de 2020
Why is the plot showing time on y axis when you are plotting as x axis ? Seems confusing
VBBV
VBBV el 7 de Dic. de 2020
Editada: VBBV el 7 de Dic. de 2020
Declare T and Velo matrices as below in the beginning before it enters for loop
%true
T = zeros(size(dens));
Velo = zeros(size(dens));
tkt = zeros(size(dens));
dens = [...]; % your values
for k = 1: length(dens)
...
...% same as before for rest of code
end
plot(app.UIAxes, tkt,T,'-b');
hold(app.UIAxes)
yyaxis right
plot(app.UIAxes, Velo, T, '-r')
kileigh palmer
kileigh palmer el 7 de Dic. de 2020
Editada: Walter Roberson el 8 de Dic. de 2020
I want to plot temperature vs the final times for each temperature. When I did that bit, the graph wasn't plotting the right values, when I tried it with the right x and y values, it still only showed values going along a straight line on the y-axis this time.
T = zeros(size(dens));
Velo = zeros(size(dens));
tkt = zeros(size(dens));
tk = zeros(size(dens));
for k...
end
plot(app.UIAxes,T, tk, '-b');
hold(app.UIAxes)
yyaxis right
plot(app.UIAxes,T,tkt, '-r');
VBBV
VBBV el 7 de Dic. de 2020
Use
%f true
delete(app.UIAxes)
In the beginning after function line to delete previous graphs drawn. Since you are using function buttons in GUI to plot, it keeps old plot axes. Next is don't use yyaxis right instead use below
%if true
plot(app.UIAxes, T, tkt, '-b')
hold(app.UIAxes)
plot(app.UIAxes, T,tk, '-r')
VBBV
VBBV el 7 de Dic. de 2020
Also clear the old values
%if true
clear T tk tkt Velo Vel ...
At the beginning of function before assigning zeros to them
kileigh palmer
kileigh palmer el 7 de Dic. de 2020
Invalid Handle?
VBBV
VBBV el 7 de Dic. de 2020
%f
delete(handles.app.UIAxes)
Try above
VBBV
VBBV el 7 de Dic. de 2020
After the plot function then update the handles GUI
%true
guidata(hObject,handles)
kileigh palmer
kileigh palmer el 7 de Dic. de 2020
Unable to resolve the name handles.app.UIAxes
VBBV
VBBV el 7 de Dic. de 2020
%true
cla reset
Use cla reset option instead of delete(handles.app.UIAxes) in the beginning and try again
Now its just graphing this:
I also added the most up to date code:
function DiameterinEditFieldValueChanged(app, event)
cla reset
D = app.DiameterinEditField.Value/12; % Diameter in ft
volume = app.Volumeft3EditField.Value;
clear T tk tkt Velo Vel
dens = [1.940 1.938 1.931 1.908 1.869];
T = zeros(size(dens));
Velo = zeros(size(dens));
tkt = zeros(size(dens));
tk = zeros(size(dens));
% Graph at various water temperatures
for k = 1:numel(dens)
...
end
end
plot(app.UIAxes,T, tkt, '-b')
hold(app.UIAxes)
plot(app.UIAxes,T,tk, '-r')
Walter Roberson
Walter Roberson el 8 de Dic. de 2020
VBBV: I think they are using App Designer instead of GUIDE.
VBBV
VBBV el 8 de Dic. de 2020
Yeah you're right

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 6 de Dic. de 2020
if ismembertol(dens(i), 1.940)

2 comentarios

kileigh palmer
kileigh palmer el 6 de Dic. de 2020
After that is says Array indices must be positive integers or logical values.
if ismembertol(dens(k), 1.940)

Iniciar sesión para comentar.

Categorías

Más información sobre Performance and Memory en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Dic. de 2020

Comentada:

el 8 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by