Find all values in an array neighbored on both sides by NaN.
Show older comments
I have an array that looks like this:
A = [1 2 4 2 NaN 2 4 NaN 6 NaN NaN 9 5 NaN];
I would like to find all values in A that have a NaN immediately adjacent on both sides. In the example above, the only value that meets this criteria is the 6. I can do it in a loop like this:
ind = false(size(A));
for n = 2:length(A)-1
if isnan(A(n-1)) && isnan(A(n+1))
ind(n)=true;
end
end
Is there a more elegant way to do this?
Accepted Answer
More Answers (0)
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!