how can i plot for loop data?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Khuram
el 1 de Dic. de 2014
Comentada: Star Strider
el 1 de Dic. de 2014
Hello everyone, I working in this heat transfer problem, but my question is about matlab code.
k=0.5; rho=2023; cv=1825; aLf=k/(rho*cv); L=0.25; nx=10; nxp=nx+1; dx=L/nx; td=12*3600; Tt=2*td;nt=60;ntp=nt+1;nTp=2*ntp;dt=td/nt; Tsd=20; Tsn=0; Ti=10; t=linspace(0,td,ntp);y=linspace(0,Tt,nTp); T1=zeros(1,ntp);T2=zeros(1,ntp); T1(1)=Ti;Tni=zeros(1,nxp); Tnii=zeros(1,nxp);
for i=1:nxp depth(i)=i*dx; for j=2:ntp time(j)= j*dt; Tx=Tsd+((Ti-Tsd)*(erf(depth(i)/(2*sqrt(aLf*(time(j))))))); T1(j)=Tx; end
subplot(223); plot(t,T1); hold on; xlabel('time (t)'); ylabel('Temperature(Tx)');grid on Tni(i)=Tx; end
time2=time; time2(1)=1;
for k=1:nxp depth(k)=k*dx; for r=1:ntp Ty=Tsn+((Tni(k)-Tsn)*(erf(depth(k)/(2*sqrt(aLf*(time2(r))))))); T2(r)=Ty; end Tnii(k)=Ty; subplot(224); plot(t,T2); hold on; xlabel('time (t)'); ylabel('Temperature(Tx)');grid on end
T=[T1,T2]; subplot(211); plot(y,T); hold on; xlabel('time (t)'); ylabel('Temperature(Tx)');grid on
my question is about the top or the first graph, its spouse to be same amount of line as in other two graph but its just drawing the last value.
can someone please help me how can i fix this, so that i can the bottom two graph into one graph.
i hope i make clear myself. Thanks in advance
0 comentarios
Respuesta aceptada
Star Strider
el 1 de Dic. de 2014
I got all the curves to plot in the top subplot by adding matrices that stored the various values of the vectors you plot in the loops. (Before, it was only plotting the last vector of ‘T1’ and ‘T2’ calculated.) The curve in the top subplot looks a bit strange, but I’ll let you sort that, since I don’t know what you’re doing or how it should look.
I’m only listing the loops here, since those are the only changes I made:
for i=1:nxp
depth(i)=i*dx;
for j=2:ntp
time(j)= j*dt;
Tx=Tsd+((Ti-Tsd)*(erf(depth(i)/(2*sqrt(aLf*(time(j)))))));
T1(j)=Tx;
end
subplot(223);
plot(t,T1); hold on; xlabel('time (t)'); ylabel('Temperature(Tx)');grid on
Tni(i)=Tx;
T1M(i,:) = T1; % Added: Store ‘T1’ Vectors In ‘T1M’
end
time2=time;
time2(1)=1;
for k=1:nxp
depth(k)=k*dx;
for r=1:ntp
Ty=Tsn+((Tni(k)-Tsn)*(erf(depth(k)/(2*sqrt(aLf*(time2(r)))))));
T2(r)=Ty;
end
Tnii(k)=Ty;
subplot(224);
plot(t,T2); hold on; xlabel('time (t)'); ylabel('Temperature(Tx)');grid on
T2M(i,:) = T2; % Added: Store ‘T2’ Vectors In ‘T2M’
end
T=[T1M T2M]; % Concatenate ‘T1M’ And ‘T2M’ To Form ‘T’
subplot(211);
plot(y,T); hold on; xlabel('time (t)'); ylabel('Temperature(Tx)');grid on
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!