MATLAB: Hi beginner need help with first time trying to use “for loop” to make a graph

for loopgraphplot

function [dT] = getdT (h,w,l,a,Tout,Theater,M)
for dt = 1:1:200 %in all honesty i just saw other people write this i have no clue what the other 1 is for
dT = 0 ;
Tin = 20+dT ;
[ V,Awall,Aroof,m ] = buildingProperties( h, w, l, a);
[Qloss] = getQloss(Tin,Tout,dt,h,w,l,a);
[Qheat] = getQheater(Tin,Theater,M,dt);
c = 1005.4;
dti = Qheat- Qloss ;
dT = 1/(m*c)*dti;
disp(Tin)
figure(1)
%dt = 1:200
plot(dt,Tin)
xlabel('dt');
ylabel('Tin');
title('Plot of dT vs dt')
end
im trying to draw a standard plot graph between time(dt) and temperature (Tin) , dt from 1 second to 200, thanks for the help

Best Answer

barry - since you are calling plot on each iteration of your for loop, then any graphics object that had been drawn on your previous iteration will be removed/deleted. You can get around this by using hold on but I don't think that you really need to do this.
Unless you have a requirement to show the updated plot on each iteration of the loop, you could just store (in an array) all the Tin values from each iteration and then do one plot outside of the loop.
You may want to review your code though
for dt = 1:1:200 %in all honesty i just saw other people write this i have no clue what the other 1 is for
dT = 0 ;
Tin = 20+dT ;
The dt and Dt are confusing - should they be different? And Tin will always be the same for each iteration of the loop. Is this intentional?
As for you comment, please review the MATLAB documentation to understand that the second one in
for dt = 1:1:200
is the step size.