I have a very long vector of data that includes gaps of "invalid" values where data that's missing has been replaced with a designated missing data value (e.g. -1) or with "NaN".
invalid_values = [-1 NaN];sample_data_vector = [22 23 22 24 -1 -1 -1 25 20 24 NaN Nan NaN 25 24 -1 -1 22 20 NaN 23];
I want to summarize info on the length of the gaps of invalid data (and no need to distinguish between whether the value is Nan or -1 or some other number). It might be helpful to know that my goal is to compare gap lengths over subsequent trials to determine whether gaps are getting longer/shorter and more/less frequent.
So for the above sample vector I'd get a matrix output that summarizes the following info about the gaps:
Length: 1 Number of occurences: 1
Length: 2 Number of occurences: 1
Length: 3 Number of occurences: 2
How would I write code to do this?
Best Answer