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!!

采纳的回答

Star Strider
Star Strider 2014-9-23
You need to subscript it so that the columns rather than the rows update:
X(:,t) = A\B;
  3 个评论
Joshua
Joshua 2014-9-23
One MOre question, How would you Plot slected rows from the X(:,t) matrix?
Star Strider
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 CenterFile Exchange 中查找有关 Title 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by