フィルターのクリア

count number of values between NaN

1 回表示 (過去 30 日間)
Dan
Dan 2011 年 7 月 12 日
Hello,
I have data set that looks something like this:
NaN; NaN; NaN; NaN; 1; 1; 1; 1; NaN; NaN; NaN; 1; NaN; NaN; NaN; NaN; NaN; NaN; NaN; 1; NaN; NaN; NaN; NaN;
I need to produce a vector of the numbers of 1's between each set of NaNs.
For example with the above data my vector would look like this:
4;1;1
Any suggestions would be greatly appreciated!
Thanks, Dan

採用された回答

Oleg Komarov
Oleg Komarov 2011 年 7 月 12 日
In = [NaN; NaN; NaN; NaN; 1; 1; 1; 1; NaN; NaN; NaN; 1; NaN; NaN; NaN; NaN; NaN; NaN; NaN; 1; NaN; NaN; NaN; NaN];
[a,b] = rude(~isnan(In));
a(b)
rude is on the FEX
  1 件のコメント
Dan
Dan 2011 年 7 月 12 日
Perfect! This is exactly what I needed.
Thank Oleg!

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 7 月 13 日
more variant
a1=In(:)';
a1(isnan(a1)) = 0;
out = diff([strfind([0 a1],[0 1])-1;strfind([a1 0],[1 0])])';

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by