Storing values from a loop into an array
조회 수: 1 (최근 30일)
이전 댓글 표시
Coding:
for t = 1:24
OT(t,1) = (((Tmax + Tmin)/2)+((Tmax - Tmin)/2)*sin(((t - 9)/12)*PI));
ST(t,1) = OT(t)-5;
B(5,1) = (-1)*Ae*(Hco*ST(t,1) + Qse(t,1));
B(10,1) = (-1)*Aw*(Hco*ST(t,1) + Qsw(t,1));
B(15,1) = (-1)*As*(Hco*ST(t,1) + Qss(t,1));
B(20,1) = (-1)*An*(Hco*ST(t,1) + Qsn(t,1));
B(27,1) = (-1)*Ar*(Hcr*ST(t,1) + Qsr(t,1));
B(28,1) = (-1)*(Qse(t,1)*Awe + Qsw(t,1)*Aww + Qss(t,1)*Aws);
B(29,1) = (-1)*(Qt(t,1))-(V*ACH*RHO*CP*1000*OT(t,1));
X = A\B;
end
I want to be able to store the values of the X matrix (29,1) of each interation into an a table of (29,24) so that i can plot the results over hour of the day.. each iteration represents the hour of the day.
Please Help!!
댓글 수: 0
채택된 답변
Star Strider
2014년 9월 23일
You need to subscript it so that the columns rather than the rows update:
X(:,t) = A\B;
댓글 수: 3
Star Strider
2014년 9월 23일
편집: Star Strider
2014년 9월 23일
My pleasure!
If you want to plot row n, define n and then plot it against t as:
n = 5;
t = 1:24;
figure(1)
plot(t, X(n,:))
if you want to plot more than one at a time, create n as a vector:
n = [3 5 7];
figure(2)
plot(t, X(n,:))
You could substitute the numbers directly (for instance X(5,:)) instead of using n, but I prefer using the variable in the event I want to use n elsewhere in the plot code. (I also number each plot with figure so I don’t overwrite them with subsequent plots. This is my personal preference but is not required.)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!