From: Andreea on 14 Jul 2010 06:02 Hello I have an incredibly large binary matrix.In this matrix let's call it A, I need to find the sequences of 1.But I need specific sequences.(like 3 ones one after another for example) For this I created a matrix of ones with one column.---->this matrix must have a specific nr of rows that I introduce from the kb. example A=[1 0 1 1 1 1 1 0 0 0 0........,1] infinite pattern=[1 1 1,1] matformed=[ _ _ _,1] of A How I did it: I break matrix A using a for loop in a smaller matrixes, based on the no of rows I need.Than I compare using isequal(mat_formed,mat ones). The problem: It takes ages. Is there a faster way to compare matrixes? The purpose: Find the no. of intervals that fit. Thank you
From: Oleg Komarov on 14 Jul 2010 06:33 "Andreea " <andreea.costache(a)ymail.com> wrote in message <i1k1uu$64f$1(a)fred.mathworks.com>... > Hello > > I have an incredibly large binary matrix.In this matrix let's call it A, I need to find the sequences of 1.But I need specific sequences.(like 3 ones one after another for example) > For this I created a matrix of ones with one column.---->this matrix must have a specific nr of rows that I introduce from the kb. > > example > A=[1 0 1 1 1 1 1 0 0 0 0........,1] infinite > pattern=[1 1 1,1] > matformed=[ _ _ _,1] of A > > How I did it: > > I break matrix A using a for loop in a smaller matrixes, based on the no of rows I need.Than I compare using isequal(mat_formed,mat ones). > > The problem: > It takes ages. Is there a faster way to compare matrixes? > > The purpose: > Find the no. of intervals that fit. > > Thank you You can give a look at findseq: http://www.mathworks.com/matlabcentral/fileexchange/28113-findseq This function retrieves the repeated value, the star index and the end index of the sequence and the length of the sequence along the specified dimension. Example: A = [1 0 0 0 1 0 1 0 1 1 0 0; 1 1 1 1 0 0 0 0 1 0 1 0]; % Find sequences along the second dimension (horizontally) Out = findseq(A,2); % Select only sequences of ones longer than 2 IDX = Out(:,1) == 1 & Out(:,4) > 2; S = Out(IDX,:) S = 1 2 8 4 So, you have one sequence of ones which starts at position 2 and ends at position 8 and is long 4 numbers (horizontally). Oleg
From: us on 14 Jul 2010 06:39 "Andreea " <andreea.costache(a)ymail.com> wrote in message <i1k1uu$64f$1(a)fred.mathworks.com>... > Hello > > I have an incredibly large binary matrix.In this matrix let's call it A, I need to find the sequences of 1.But I need specific sequences.(like 3 ones one after another for example) > For this I created a matrix of ones with one column.---->this matrix must have a specific nr of rows that I introduce from the kb. > > example > A=[1 0 1 1 1 1 1 0 0 0 0........,1] infinite > pattern=[1 1 1,1] > matformed=[ _ _ _,1] of A > > How I did it: > > I break matrix A using a for loop in a smaller matrixes, based on the no of rows I need.Than I compare using isequal(mat_formed,mat ones). > > The problem: > It takes ages. Is there a faster way to compare matrixes? > > The purpose: > Find the no. of intervals that fit. > > Thank you one of the many solutions m=[1,1,0,1,1,1,0,1,1,0,1,0]; p=[1,1]; % <- pattern... ix=strfind(m,p) % ix = 1 4 5 8 % <- note: overlap(!)... % -or- s=char(m+'0'); ix=regexp(s,char(p+'0')) % ix = 1 4 8 % <- note: NO overlap(!)... % -or- donwload this FEX submission http://www.mathworks.com/matlabcentral/fileexchange/1518 us
|
Pages: 1 Prev: changing MATLAB window title to the name of the active document in the editor Next: ModelSim |