필터 지우기
필터 지우기

count number of values between NaN

조회 수: 4 (최근 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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by