Filter löschen
Filter löschen

count number of values between NaN

1 Ansicht (letzte 30 Tage)
Dan
Dan am 12 Jul. 2011
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

Akzeptierte Antwort

Oleg Komarov
Oleg Komarov am 12 Jul. 2011
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 Kommentar
Dan
Dan am 12 Jul. 2011
Perfect! This is exactly what I needed.
Thank Oleg!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 13 Jul. 2011
more variant
a1=In(:)';
a1(isnan(a1)) = 0;
out = diff([strfind([0 a1],[0 1])-1;strfind([a1 0],[1 0])])';

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by