plotting in for loop

조회 수: 1 (최근 30일)
Yusuf Ziya ÜNEL
Yusuf Ziya ÜNEL 2020년 7월 5일
댓글: Yusuf Ziya ÜNEL 2020년 7월 6일
I tried to plot a linear continious graph but my graph shows only specific dots. I tried to turn my output data of for loop but an error comes up. Can anyone help me to plot a decent graph?
length_1 = 20; % house length parameters
length_2 = 10;
length_3 = 4;
beta = 40; % roof angle
N_win = 4; % number of windows
N_wall = 1; % number of walls "all in one'
areaWin = 1; % area of windows
areaWall = 236; % area off walls
thermWall = 136.8; % wall thermal coeffient
thermWin = 2808; % window thermal coeffient
thickWin = 0.07; % thickness of wind
thickWall = 0.2; % thickness of walls
airDen = 1.225; % air density
ca = 1.01; % thermal capasity of air
COP = 2; % coeffiecient of performance
P = 3; % power 3KW
Volume = (length_1*length_2*length_3) + (tand(beta)*length_1*length_2); %house volume
mass = Volume*airDen;
R_win = (1/N_win) * (thickWin/(thermWin*areaWin)); %resistance of windows
R_wall = (1/N_wall) * (thickWall/(thermWall*areaWall)); %resistance of walls
Rh = 1/(1/R_wall + 1/R_win); %paralel circuit
fprintf("Volume = %f\n",Volume)
fprintf("Mass = %f\n",mass)
fprintf("Walls' R = %f\n",R_wall)
fprintf("Windows' R = %f\n",R_win)
fprintf("Rh = %f\n\n",Rh)
deltaT = 0.1; %6 minutes period of an hour = 6/60
Tini = 19; %initial temp starts with fav temp of household's owner
Ptotal = 0; %total power consumption counter
for t = 12:0.1:16 %Time between 12-16 o'clock
Tout=0;
fprintf("Time = %.2f\n",t);
fprintf("Tin,h = %.2f\n\n",Tini);
plot(t,Tini,"r-o")
grid on
hold off
if (t>12) && (t<14.1)
Tout = 30; %12am-14am outside temperature
elseif (t>14) && (t<15.1)
Tout = 31; %14am-15am outside temperature
elseif (t>15) && (t<16.1)
Tout = 30; %15am-16am outside temperature
end
if Tini<21
U = 0; %HVAC is OFF
else
U = 1; %HVAC is ON
end
hold on
Tini=((1-(deltaT/(1000*mass*Rh)))*Tini+(deltaT/(1000*mass*Rh))*Tout-U*((COP*P*deltaT)/(0.000277*mass*ca)));
Ptotal = Ptotal + P*U; %total power
end
fprintf("Total Power Consumption = %.d KW\n",Ptotal)

답변 (1개)

darova
darova 2020년 7월 5일
See my recommendations
  댓글 수: 3
darova
darova 2020년 7월 6일
can you show the code?
Yusuf Ziya ÜNEL
Yusuf Ziya ÜNEL 2020년 7월 6일
length_1 = 20; %house length parameters
length_2 = 10;
length_3 = 4;
beta = 40; %roof angle
N_win = 4; %number of windows
N_wall = 1; %number of walls "all in one"
areaWin = 1; %area of windows
areaWall = 236; %area off walls
thermWall = 136.8; %wall thermal coeffient
thermWin = 2808; %window thermal coeffient
thickWin = 0.07; %thickness of windows
thickWall = 0.2; %thickness of walls
airDen = 1.225; %air density
ca = 1.01; %thermal capasity of air
COP = 2; %coeffiecient of performance
P = 3; %power 3KW
Volume = (length_1*length_2*length_3) + (tand(beta)*length_1*length_2); %house volume
mass = Volume*airDen;
R_win = (1/N_win) * (thickWin/(thermWin*areaWin)); %resistance of windows
R_wall = (1/N_wall) * (thickWall/(thermWall*areaWall)); %resistance of walls
Rh = 1/(1/R_wall + 1/R_win); %paralel circuit
fprintf("Volume = %f\n",Volume)
fprintf("Mass = %f\n",mass)
fprintf("Walls' R = %f\n",R_wall)
fprintf("Windows' R = %f\n",R_win)
fprintf("Rh = %f\n\n",Rh)
t = 12:0.1:16;
deltaT = 0.1; %6 minutes period of an hour = 6/60
Tini = 19; %initial temp starts with fav temp of household's owner
Tout = 30; %for debugging
Ptotal = 0; %total power consumption counter
for i = 1:length(t)
fprintf("Time = %.2f\n",t);
fprintf("Tin,h = %.2f\n\n",Tini);
plot(t,Tini);
xlabel("Time")
ylabel("T_in,h")
grid on
if t(i)>12 && t(i)<14.1
Tout = 30; %12am-14am outside temperature
elseif t(i)>14 && t(i)<15.1
Tout = 31; %14am-15am outside temperature
elseif t(i)>15 && t(i)<16.1
Tout = 30; %15am-16am outside temperature
end
if Tini(i)<21
U = 0; %HVAC is OFF
else
U = 1; %HVAC is ON
end
hold on
Tini(i+1)=((1-(deltaT/(1000*mass*ca*Rh)))*Tini(i)+(deltaT/(1000*mass*ca*Rh))*Tout-U*((COP*P*deltaT)/(0.000277*mass*ca)));
Ptotal = Ptotal + P*U; %total power
end
fprintf("Total Power Consumption = %.d KW\n",Ptotal)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Electrical Block Libraries에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by