Info
此问题已关闭。 请重新打开它进行编辑或回答。
Help. I'm trying to created a code that...........
1 次查看(过去 30 天)
显示 更早的评论
I'm trying to created a code that doing something like this, when v (time serie) changes only from negative to positive (zero crossings),this was separated by at least 4 elements from other zero crossings(left and right direction), and if I take 8 elements (from zero crossings)to the right, at least the 80% of the elements were positive,and if i take 6 elements to the left (from zero crossings), at least the 60% of the elements were negative. (I have a huge data serie , and I'm trying to generate a code that I can rearrange the parameters.
Regards)
v=[-1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 -1 -1
1 -1 -1 1 1 1 1 1 1 1 1 -1 1]
regards,
4 个评论
回答(2 个)
Andrei Bobrov
2013-7-16
a = v == 1;
ii = [true;diff(a(:)) ~= 0];
i0 = find(ii);
iii = reshape(diff([i0;numel(a)+1]),2,[])';
i1 = reshape(i0,2,[])';
indexout = i1(all(bsxfun(@le,[.6 .8],bsxfun(@rdivide,iii,[6 8])),2),2);
Jan
2013-7-17
编辑:Jan
2013-7-17
[value, rep, index] = RunLength(v);
n = numel(value);
match = zeros(1, n); % Pre-allocate
iMatch = 0;
first = find(index > 6, 1, 'first'); % Or <= ?
last = find(index < numel(v) - 8, 1, 'last'); % Or <= ?
for k = first:last
if n(k-1) < 4 && n(k) < 4 % Or <= ?
continue;
end
q = index(k);
if sum(v(q:q+7) == 1) / 8 < 0.8 % Or q+1:q+8 ?
continue;
end
if sum(v(q-6:q-1) == 1) / 6 < 0.6 % Or q-5:q ?
continue;
end
% All conditions match:
iMatch = iMatch + 1;
match(iMatch) = k;
end
match = match(1:iMatch);
Some points are not clear yet, e.g. if "8 elements to the right" is inclusive or exclusive the current element. But if this is cleared, e.g. the conditiosn could be vectorized easily. But it is not sure if this is faster and perhaps the speed of the loop is sufficient already.
0 个评论
此问题已关闭。
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!