help with storing i,j loop results?

20 views (last 30 days)
arkedia
arkedia on 21 Dec 2014
Answered: Stephen23 on 21 Dec 2014
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 Comment
Stephen23
Stephen23 on 21 Dec 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.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 21 Dec 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:

More Answers (0)

Community Treasure Hunt

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

Start Hunting!