loop error

4 views (last 30 days)
Tian Lin
Tian Lin on 28 Mar 2011
x=[1.1 2.4 3.1 4.8 5.9 6.2 7.9 8.9 9.7 10.3 11.2 12.6 13.7 14.2 15.9 16.8 17.0 18.5 19.6 20.3 21.7 22.6 23.8 24.7 25.9 26.1 27.8 28.9 29.4 30.6 31.7 32.1 33.5 34.1 35.2 36.9 37.8];
n = length(x);
L = floor(n/5);
N = n;
for a=1:N-L*4;
T=cell(a,L);
for jj = 1:L;
S = jj;
n = zeros(1,floor((N-a)/(S))+1);
for ii = 1:length(n)
n(ii) = x(S*(ii)+(a-S));
end
T{a,jj} = n;
end
end
I have this code to get data from x. 'a' is the start number, I want to do a loop like 'for a=1:N-L*4',but the answer is only when a=N-L*4, there is no a=1,a=2,... What's wrong with my loop?

Accepted Answer

Andrew Newell
Andrew Newell on 28 Mar 2011
You're creating T on each iteration of the loop. Remove
T = cell(a,L);
and put
T = cell(N-L*4,L);
above for a=1:N-L*4.
  1 Comment
Tian Lin
Tian Lin on 29 Mar 2011
it works!thanks!

Sign in to comment.

More Answers (0)

Categories

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

Tags

Products

Community Treasure Hunt

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

Start Hunting!