From: 1986 on 5 Aug 2010 18:52 Hi everyone, I'm new here and a begginer at matlab. I have vector with elements 0 and 1. Vector length is 300. I need to find the longest array of 1 and its location in vector. Does anyone have any suggestions? Thank you in advance, Milana
From: Matt J on 5 Aug 2010 18:59 If you have the Image Processing Toolbox, use bwconncomp() and regionprops().
From: Roger Stafford on 5 Aug 2010 20:19 "1986 " <milanaplecas(a)gmail.com> wrote in message <i3ffak$8qm$1(a)fred.mathworks.com>... > Hi everyone, > I'm new here and a begginer at matlab. > I have vector with elements 0 and 1. Vector length is 300. > I need to find the longest array of 1 and its location in vector. > Does anyone have any suggestions? > Thank you in advance, > Milana - - - - - - - - - If you don't have the image processing toolbox, you can do this. Let the vector of 1's and 0's be a row vector. t = diff([0,v,0]); p1 = find(t==1); p2 = find(t==-1); [m,p] = max(f2-f1); b = p1(p); e = p2(p)-1; m is the length of the longest sequence of ones, b is the index of its first element and e is the index of its last element. Roger Stafford
From: 1986 on 6 Aug 2010 07:01 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i3fkdp$mcr$1(a)fred.mathworks.com>... > "1986 " <milanaplecas(a)gmail.com> wrote in message <i3ffak$8qm$1(a)fred.mathworks.com>... > > Hi everyone, > > I'm new here and a begginer at matlab. > > I have vector with elements 0 and 1. Vector length is 300. > > I need to find the longest array of 1 and its location in vector. > > Does anyone have any suggestions? > > Thank you in advance, > > Milana > - - - - - - - - - > If you don't have the image processing toolbox, you can do this. Let the vector of 1's and 0's be a row vector. > > t = diff([0,v,0]); > p1 = find(t==1); > p2 = find(t==-1); > [m,p] = max(f2-f1); > b = p1(p); > e = p2(p)-1; > > m is the length of the longest sequence of ones, b is the index of its first element and e is the index of its last element. > > Roger Stafford Thank you Roger, It is exactly what I'm looking for. Milana
|
Pages: 1 Prev: another for loop issue Next: Initial Value Problem - ode45 returns NaN |