count number of values between NaN

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일

0 개 추천

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일

0 개 추천

more variant
a1=In(:)';
a1(isnan(a1)) = 0;
out = diff([strfind([0 a1],[0 1])-1;strfind([a1 0],[1 0])])';

카테고리

도움말 센터File Exchange에서 NaNs에 대해 자세히 알아보기

질문:

Dan
2011년 7월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by