Row numbers of the first zero, repeated

3 Ansichten (letzte 30 Tage)
Mat
Mat am 30 Okt. 2014
Bearbeitet: Mat am 31 Okt. 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...

Akzeptierte Antwort

Image Analyst
Image Analyst am 30 Okt. 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 Kommentar
Mat
Mat am 31 Okt. 2014
Bearbeitet: Mat am 31 Okt. 2014
Thanks, works perfectly. No I wasn't interested in the first element.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by