MATLAB Answers

# Using isnan to check if there is any NaNs in a window and setting all the values to NaN if there are any.

14 views (last 30 days)
Gus Abraham on 2 Mar 2021
Answered: Walter Roberson on 2 Mar 2021
I'm trying to use isnan to find if there is any NaNs in y in a window of 12 time points and if there are set all values for X in the window to NaN. but I'm running into some issues.
This is the code I've used
for i=1:11:T;
for k=1:3;
if isnan(y(i:i+11,k));
X(i:i+11,k) =NaN;
end
end
end
The part I believe is the issue is "if isnan(x(i:i+11,k))", because if I use if isnan(x(i,k)) it works but then it only sets X(i:i+11,k) to NaN if the i'th y is NaN (i.e it doesn't check the whole window)
Any ideas of what I could do?
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Walter Roberson on 2 Mar 2021
for i=1:11:T;
for k=1:3;
if any(isnan(y(i:i+11,k)))
X(i:i+11,k) =NaN;
end
end
end
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!