フィルターのクリア

Row numbers of the first zero, repeated

3 ビュー (過去 30 日間)
Mat
Mat 2014 年 10 月 30 日
編集済み: Mat 2014 年 10 月 31 日
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...

採用された回答

Image Analyst
Image Analyst 2014 年 10 月 30 日
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 件のコメント
Mat
Mat 2014 年 10 月 31 日
編集済み: Mat 2014 年 10 月 31 日
Thanks, works perfectly. No I wasn't interested in the first element.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by