Info

此问题已关闭。 请重新打开它进行编辑或回答。

Help. I'm trying to created a code that...........

1 次查看(过去 30 天)
Javier
Javier 2013-7-16
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
Jan
Jan 2013-7-17
How large is "huge"? It matters if you want to process 1GB of data or only some MB.
Javier
Javier 2013-7-17
编辑:Javier 2013-7-17
Hello Jan, are only a few mb...
>> size(v)
ans =
1 180407
regards

回答(2 个)

Andrei Bobrov
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);
  1 个评论
Javier
Javier 2013-7-17
编辑:Javier 2013-7-17
Thank you so much Andrei, but for example, if I wanna (rearrange the parameters) change this part of the code("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)"), change 4 by 10, or other number
regards

Jan
Jan 2013-7-17
编辑:Jan 2013-7-17
Try a simple FOR loop at least as a proof of concept: (See FEX: RunLength)
[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.

此问题已关闭。

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by