DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Legacy and Other Languages (http://www.daniweb.com/forums/forum42.html)
-   -   matlab loop problem (http://www.daniweb.com/forums/thread194584.html)

Bisaye May 29th, 2009 8:06 am
matlab loop problem
 
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

Bisaye Jun 5th, 2009 6:47 am
Re: matlab loop problem
 
Quote:

Originally Posted by Bisaye (Post 878869)
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


All times are GMT -4. The time now is 8:17 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC