Clear Filters
Clear Filters

How to save values of loops ?

2 views (last 30 days)
Fox
Fox on 4 Jan 2016
Commented: Fox on 4 Jan 2016
I made the following for loop and now want to save the different values I get on my command window in one vector: My Problem is that the following code doesn't work.
be=zeros(16,1);
for s=1:2:16
bety1=((z3(0+s:1+s,1:20)*z3(0+s:1+s,1:20)')^-1)*(z3(0+s:1+s,1:20)*y3(1:20));
be(s)=bety1
end
Can somebody help me ? Perhaps you need the info that at every bety1 I get a vector with 2 rows so in the end I should have a vektor with 16 rows.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 4 Jan 2016
be=zeros(16,1);
for s=1:2:16
bety1=((z3(0+s:1+s,1:20)*z3(0+s:1+s,1:20)')^-1)*(z3(0+s:1+s,1:20)*y3(1:20));
be(s:s+1)=bety1
end
  1 Comment
Fox
Fox on 4 Jan 2016
Thanks. Could you perhaps help me with the following similar problem ? Here I want to do the same but with the double for loop it doesn't work. End should be a matrix with 16 rows and 41 colums.
bee=zeros(16,41)
for i=1:41
for k=1:2:16
bety2=((z3(0+k:1+k,1+i:20+i)*z3(0+k:1+k,1+i:20+i)')^-1)*(z3(0+k:1+k,1+i:20+i)*...
y3(1+i:20+i));
bee(k:k+1,i:i+1)=bety2
end
end

Sign in to comment.

More Answers (0)

Categories

Find more on Sparse Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!