How can I change the value of a variable during a while loop?

3 views (last 30 days)
I'm trying to create a matrix that selects 29 pieces of data from a matrix 'ozonewest' that is 156x1 in size.
Then, for each iteration of the loop, I want to move the data selected along by one i.e. 1-29, and then 2-30 etc. This would occur 126 times until there are no more data to use.
My code:
TimeSeries=ones(29,126); % Matrix I'm inputting the data into
dt=28;
nt=126;
i1=1;
for i2=i1+dt;
while i2<=nt;
tmp=ozonewest(i1:i2,1);
TimeSeries(:,i1)=tmp;
i1=i1+1;
end
end
My problem is the last line of code, i1=i1+1; only works once (value of 2 in the workspace) and it gives me the Subscripted assignment dimension mismatch error.
Any help would be great. Thanks.
  1 Comment
Adam
Adam on 22 Oct 2015
for i2=i1+dt;
is just going to evaluate to
for 29
isn't it? i.e. not a loop at all. You can't have a for loop based on an 'i1' variable that is constantly changing within that same loop.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!