MATLAB Answers

How to store the result of a loop in a cell?

조회 수: 1(최근 30일)
Joseph
Joseph 17 Jan 2019
Commented: Joseph 17 Jan 2019
Hi everyone
i have a matrix R(12*44) and X(12*1). i'm trying to take a linear regression for each column of matrix R in a for loop and store in a cell such as b, but seems like it just stores the regression of the last column. can you please help. here is the script that i'm using.
X=[ones(size(R(:,1))) X];
b=cell(44,1);
for i=44
c=regress(R(:,i),X);
b{i}=c;
end;
Thank you

  댓글 수: 0

로그인 to comment.

채택된 답변

Stephen Cobeldick
Stephen Cobeldick 17 Jan 2019
Stephen Cobeldick 님이 편집함. 17 Jan 2019
Your code is only iterating once, because
for i = 1:44
^^ you forgot this.
PS: I would recomend using ii or k as the loop iterator variable, because i is the imaginary unit.

  댓글 수: 1

Joseph
Joseph 17 Jan 2019
Oh shoot, i'm an idiot. you wouldn't believe if i told you i was thinking about this for like 5 hours! thanks :|

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by