943,672 Members | Top Members by Rank

Ad:
May 29th, 2009
0

matlab loop problem

Expand 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
Last edited by Tekmaven; May 30th, 2009 at 3:13 am. Reason: Code Tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bisaye is offline Offline
10 posts
since May 2009
Jun 5th, 2009
0

Re: matlab loop problem

Click to Expand / Collapse  Quote originally posted by Bisaye ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bisaye is offline Offline
10 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Legacy and Other Languages Forum Timeline: ANSI lisp compiler
Next Thread in Legacy and Other Languages Forum Timeline: datestr





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC