Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

1 visualizzazione (ultimi 30 giorni)
Javier
Javier il 16 Lug 2013
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commenti
Jan
Jan il 17 Lug 2013
How large is "huge"? It matters if you want to process 1GB of data or only some MB.
Javier
Javier il 17 Lug 2013
Modificato: Javier il 17 Lug 2013
Hello Jan, are only a few mb...
>> size(v)
ans =
1 180407
regards

Risposte (2)

Andrei Bobrov
Andrei Bobrov il 16 Lug 2013
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 Commento
Javier
Javier il 17 Lug 2013
Modificato: Javier il 17 Lug 2013
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 il 17 Lug 2013
Modificato: Jan il 17 Lug 2013
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.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by