help with storing i,j loop results?

4 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2014-12-21
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.

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2014-12-21
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 个)

Community Treasure Hunt

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

Start Hunting!

Translated by