How to count sequential NaN values
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!