フィルターのクリア

How to find the second zero element in an array?

8 ビュー (過去 30 日間)
Leo Müller
Leo Müller 2015 年 11 月 11 日
コメント済み: Leo Müller 2015 年 11 月 11 日
Hello, I have the following problem: I would like to find the second non zero element in an array such as: array = [ 0 138 49 47 0 0 0 0] What I want is the index 5. Thank you for your help!

採用された回答

Mohammad Abouali
Mohammad Abouali 2015 年 11 月 11 日
編集済み: Mohammad Abouali 2015 年 11 月 11 日
index 5 is zero? You said you are looking for non-zero?!!!
anyway you can use find().
something like this:
myArray=[ 0 138 49 47 0 0 0 0];
idx=find(myArray==0,2,'first');
if (numel(idx)<2)
error('less than 2 elements were found');
end
idx=idx(end)
idx =
5
  1 件のコメント
Leo Müller
Leo Müller 2015 年 11 月 11 日
Thank you, this is what I was looking for!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by