matlab loop problem

Thread Solved

Join Date: May 2009
Posts: 10
Reputation: Bisaye is an unknown quantity at this point 
Solved Threads: 0
Bisaye Bisaye is offline Offline
Newbie Poster

matlab loop problem

 
0
  #1
May 29th, 2009
Hi
I am woring on a for loop to extract selected datas from matlab workspace.The program has some problem to give you an idea what it all about. I want to read 12 datas which follow some pattern in my case every 10 datas that follow a criteria 20 first and then 2 read the 10 datas that follow and 2 and 20 also,these numbers and the data are infinitely many.
so I wrote a code
j=1;
i=1;
N=length(B); % B is the one dimensional vector which has the %whole datas
for  i=1:1:N
    if ((B(i)==20) && (B(i+1)==2))
        c(j)=i;
        j=j+1;
    end
end
M=length(b);
k=1;
s=1;
D=ones(12,1);
for k=1:1:M
    l=c(k);
    for s=1:1:12
        D(s)=B(l);
        l = (l+1);
    end
end
now what I want as input for another code is D but what the code reads is like
the first value and after the next iteration the first and the second value and it coninues reading like this. So I would like some idea how to read the 10 data's that follow 20&10 every time and allocate the values to D.
Many Thanks
Last edited by Tekmaven; May 30th, 2009 at 3:13 am. Reason: Code Tags
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: Bisaye is an unknown quantity at this point 
Solved Threads: 0
Bisaye Bisaye is offline Offline
Newbie Poster

Re: matlab loop problem

 
0
  #2
Jun 5th, 2009
Originally Posted by Bisaye View Post
Hi
I am woring on a for loop to extract selected datas from matlab workspace.The program has some problem to give you an idea what it all about. I want to read 12 datas which follow some pattern in my case every 10 datas that follow a criteria 20 first and then 2 read the 10 datas that follow and 2 and 20 also,these numbers and the data are infinitely many.
so I wrote a code
j=1;
i=1;
N=length(B); % B is the one dimensional vector which has the %whole datas
for  i=1:1:N
    if ((B(i)==20) && (B(i+1)==2))
        c(j)=i;
        j=j+1;
    end
end
M=length(b);
k=1;
s=1;
D=ones(12,1);
for k=1:1:M
    l=c(k);
    for s=1:1:12
        D(s)=B(l);
        l = (l+1);
    end
end
now what I want as input for another code is D but what the code reads is like
the first value and after the next iteration the first and the second value and it coninues reading like this. So I would like some idea how to read the 10 data's that follow 20&10 every time and allocate the values to D.
Many Thanks
I solved the problem many thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Legacy and Other Languages Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC