How can I plot values of a for loop?
Show older comments
Hey guys, when I run this code I get an output with every value for Tc and Q. But these values won't plot, I just get a blank plot with no dots or lines. I have tried using both plot and plotyy, none of them work. Please help me.
%Given values:
d=0.35; % (m)
k=14.9; % (W/m.K)
r=d/2;
ro=7900; % (kg/m^3)
cp=0.477; % (kJ/kg.K)
a=3.95*10^-6; % (m^2/s)
Ti=400+273; % (K)
h=60; % (W/m^2.K)
Ts=150+273; % (K)
%Finding biot number:
Bi=(h*r/k);
%Values obtained from table:
l=1.0935; %lambda
A=1.1558;
J=0.4689;
%Finding Qmax:
m=ro*pi*r^2*1;
Qmax=m*cp*(Ti-Ts);
Tc=0;
Q=0;
%Generating temperature and heat transfer numbers
for t=5*60:60:60*60
tau=((t*a)/r^2);
Tc=(Ts+((Ti-Ts)*(A*exp(l^2*(-tau)))))
Q=(Qmax*(1-(2*((Tc-Ts)/(Ti-Ts))*(J/l))))
end
t=[5*60:60:60*60];
%ploting values
[hAx,hLine1,hLine2] = plotyy(t,Tc,t,Q)
xlabel('Time (s)')
ylabel(hAx(1),'Center temperature (K)')
ylabel(hAx(2),'Heat transfer (kJ)')
title('Center temperature and heat transfer as a function of time')
Accepted Answer
More Answers (1)
Patricia
on 30 Nov 2014
1 Comment
Star Strider
on 30 Nov 2014
See if subscripting ‘t’ as ‘t(k)’ corrects that.
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!