help with storing i,j loop results?

조회 수: 4 (최근 30일)
arkedia
arkedia 2014년 12월 21일
답변: Stephen23 2014년 12월 21일
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개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by