help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: filtering logical array


From: seektime
Subject: Re: filtering logical array
Date: Tue, 26 Jun 2012 14:39:43 -0700 (PDT)

Thanks Jordi, here's an expansion of your suggestion and a solution.

% Logical vector to filter.
a=[0 0 1 1 1 1 1 0 1 0 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1 1 0]';

d = diff(a);
s = find(d > 0) + 1;
e = find(d < 0) + 1;
n = e - s;

min_seq_len = 2; % minimal length of consecutive 1's

M=[s e n];
idx = find(M(:,3) >= min_seq_len);
M(idx,:) = []; % eliminate elements which obey "min_seq_len"
M = M(:,1:2);
ro = size(M);
v = [];
for i=1:ro
        tmp = M(i,1):M(i,2);
        v = [v;tmp(:)];
end

a_filter = a; 
a_filter(v)=false;

[a a_filter]

--
View this message in context: 
http://octave.1599824.n4.nabble.com/filtering-logical-array-tp4630983p4630995.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]