Effacer les filtres
Effacer les filtres

Row numbers of the first zero, repeated

3 vues (au cours des 30 derniers jours)
Mat
Mat le 30 Oct 2014
Modifié(e) : Mat le 31 Oct 2014
I have a column vector of 7000 data points... of the pattern 0 0 0 0 30 60 90 120 119 118.... 2 1 0 0 0
I want to return the row number for the last cell before the number turns into a 0, every time this happens
Note: All the numbers are variable, and the sequences I want to extract varies in length.
To pick out the maximums I used [pks locs]=findpeaks(a(:,1)), want to do similar for just before the zeroes appear...

Réponse acceptée

Image Analyst
Image Analyst le 30 Oct 2014
Your first element is a zero. Should that be included in the output? So you just want the last non-zero number in a stretch of non-zero numbers before it turns into a 0, right? Try this:
m = [0 0 0 0 30 60 90 120 119 118 2 1 0 0 0 3 4 0] % Create sample data.
dm = diff(m~=0) % Threshold and find element-to-element differences.
lastElements = find(dm == -1) % Find the indexes where it goes to zero.
  1 commentaire
Mat
Mat le 31 Oct 2014
Modifié(e) : Mat le 31 Oct 2014
Thanks, works perfectly. No I wasn't interested in the first element.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by