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)
回答 (2 件)
VBBV
2020 年 12 月 6 日
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 件のコメント
Walter Roberson
2020 年 12 月 6 日
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.)
kileigh palmer
2020 年 12 月 6 日
VBBV
2020 年 12 月 6 日
Why is the plot showing time on y axis when you are plotting as x axis ? Seems confusing
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
2020 年 12 月 7 日
編集済み: Walter Roberson
2020 年 12 月 8 日
VBBV
2020 年 12 月 7 日
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
2020 年 12 月 7 日
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
2020 年 12 月 7 日
VBBV
2020 年 12 月 7 日
%f
delete(handles.app.UIAxes)
Try above
VBBV
2020 年 12 月 7 日
After the plot function then update the handles GUI
%true
guidata(hObject,handles)
kileigh palmer
2020 年 12 月 7 日
VBBV
2020 年 12 月 7 日
%true
cla reset
Use cla reset option instead of delete(handles.app.UIAxes) in the beginning and try again
kileigh palmer
2020 年 12 月 7 日
Walter Roberson
2020 年 12 月 8 日
VBBV: I think they are using App Designer instead of GUIDE.
VBBV
2020 年 12 月 8 日
Yeah you're right
Walter Roberson
2020 年 12 月 6 日
if ismembertol(dens(i), 1.940)
2 件のコメント
kileigh palmer
2020 年 12 月 6 日
Walter Roberson
2020 年 12 月 6 日
if ismembertol(dens(k), 1.940)
カテゴリ
ヘルプ センター および File Exchange で Performance and Memory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


