Row numbers of the first zero, repeated

2 visualizzazioni (ultimi 30 giorni)
Mat
Mat il 30 Ott 2014
Modificato: Mat il 31 Ott 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...

Risposta accettata

Image Analyst
Image Analyst il 30 Ott 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 Commento
Mat
Mat il 31 Ott 2014
Modificato: Mat il 31 Ott 2014
Thanks, works perfectly. No I wasn't interested in the first element.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by