How to count sequential NaN values
1 view (last 30 days)
Show older comments
Hello,
I have a matrix
x = [1,NaN,3;4,NaN,6;7,NaN,NaN;1,2,NaN;3,NaN,3;NaN,9,1]
creates
1 NaN 3
4 NaN 6
7 NaN NaN
1 2 NaN
3 NaN 3
NaN 9 1
I want to be able to write to a variable every time a series of NaN (1 or more) occur in a column, and how many.
For example for the above code I want it to calculate
1 occurance for column 1 for 1 instance
1 occurance for column 2 for 3 instances
1 occurance for column 2 for 1 instance
1 occurance for column 3 for 2 instances
Do I put in a for loop for each column, search for NaN, then use "Diff" to find a difference of zero, then record how many gaps there are?
Or, do I delete every NaN value, then search for gaps in the data and use "Diff" like below?
threshold = 5;
gap = diff(data1);
idx = find(gap>threshold);
Thank you.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!