interpolate NaNs only if less than 4 consecutive NaNs
이전 댓글 표시
Hello,
I have a vector of datapoints containing some NaNs. I'd like to interpolate the NaNs only if there are 3 or less consecutive NaNs. i.e. interpolate over short datagaps but not long ones.
Any ideas would be welcome. Thanks
댓글 수: 6
Oleg Komarov
2012년 4월 4일
Please post a minimum working example.
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Daniel Shub
2012년 4월 4일
Are you asking for help with the interpolation or identifying short and long sequences of nans?
Lindsey
2012년 4월 5일
Jan
2012년 4월 5일
Please insert additional information by editing the original question instead of adding a comment.
Lindsey
2012년 4월 12일
Soni huu
2012년 6월 28일
what about if the NaN is 2 space(" ") can you solve?
채택된 답변
추가 답변 (1개)
Geoff
2012년 4월 4일
Okay, here's a fun way to find the long sequences. You could interpolate the entire lot and then set the long sequences back to NaN. I'm using regexp because it's powerful =)
n = reshape(isnan(x), numel(x), 1); % ensure row-vector
[a, b] = regexp( char(n+'A'), 'B{4,}', 'start', 'end' );
This does string matching on sequences of 'B' (NaN) that are 4 characters or longer, and returns their start and end indices into the vectors a and b.
The nice thing about this is you can mess around with the regular expression to detect exactly what you want.
For example, to get only the indices of sequences with 3 or less NaNs, incorporating the non-NaN on either side, you would use:
'AB{1,3}A'
What you do with the indices is up to you.
댓글 수: 2
Jan
2012년 4월 12일
The reshaping of x can be simplified: "n = x(:)". Although I confuse this frequently, I think that this is a column vector, not a row vector.
The REGEXP method is nice. +1
It should be possible to use "conv(isnan(x), ones(1,4))" also.
Geoff
2012년 4월 12일
Oh yeah, I didn't think of just doing:
n = isnan(x(:));
I thought at the time: "okay I want isnan(x)(:) but I can't do that!"
Duhhh. =)
카테고리
도움말 센터 및 File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!