Storing values from a loop into an array
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Star Strider
il 23 Set 2014
You need to subscript it so that the columns rather than the rows update:
X(:,t) = A\B;
3 Commenti
Star Strider
il 23 Set 2014
Modificato: Star Strider
il 23 Set 2014
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.)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!