help with storing i,j loop results?
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
the following code,i use it to calculate a statistic. note:the statistic is (AIC) used in regression rand time series identification the first for loop i stored all result as
A 1 2 3 4 5
B 12 17 6 13 8
not A is ind and B is aic result BUT the second for loop i don't know how to get results as i did in the previous loop
i want store all the loop results taking in account that the ind (index) in second loop is (i,j)
for i=1:5
a=i;
ind=[a]
one=x(:,[i])
[b_LS, sigma_b_LS, s_LS] = lscov(one,y)
s = s_LS
aicx1=size(one,1)*log(s)+2*size(one,2)
A(i)=vertcat(ind)
B(i)=vertcat(aicx1)
end
aic1=[A;B]
m=[]
for i=1:4
for j=2:5
if i<j
a=i;
b=j;
ind=[a,b]
two=x(:,[i,j])
[b_LS, sigma_b_LS, s_LS] = lscov(two,y)
s = s_LS
aicx2=size(two,1)*log(s)+2*size(two,2)
end
end
end
what can i do? Thanks
1 Commento
Stephen23
il 21 Dic 2014
Do not use i or j for your loop variables, as these are the names of the inbuilt imaginary unit . Shadowing the standard functions and variables like this is usually a bad idea.
Risposta accettata
Stephen23
il 21 Dic 2014
You can extend the concept you used in the first loop to arrays with more dimensions, ie matrices:
You might also like to read about vectorization:
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Time Series Objects 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!