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