How to make a number NaN when its both neighbours are NaN?
1 回表示 (過去 30 日間)
古いコメントを表示
I would like to find the numbers sandwiched between two NaN's and make them NaN.
I have a matrix:
A = [NaN 2.35 NaN 2.358 1.68 1.98 2.88 NaN 2.68 NaN 2.70 NaN 2.20 NaN 3.03; NaN NaN 2.77 NaN 2.67 1.87 2.56 1.88 2.39 NaN 2.77 2.83 NaN 2.59 NaN];
I would like to check the numbers that is sourrounded by NaN values on both the sides.
If the number has NaN on both sides, then make that number as NaN;
I want the output to be like,
B = = [NaN NaN NaN 2.358 1.68 1.98 2.88 NaN NaN NaN NaN NaN NaN NaN 3.03; NaN NaN NaN NaN 2.67 1.87 2.56 1.88 2.39 NaN 2.77 2.83 NaN NaN NaN];
0 件のコメント
採用された回答
Chunru
2022 年 7 月 28 日
A = [NaN 2.35 NaN 2.358 1.68 1.98 2.88 NaN 2.68 NaN 2.70 NaN 2.20 NaN 3.03;
NaN NaN 2.77 NaN 2.67 1.87 2.56 1.88 2.39 NaN 2.77 2.83 NaN 2.59 NaN];
B = [NaN NaN NaN 2.358 1.68 1.98 2.88 NaN NaN NaN NaN NaN NaN NaN 3.03;
NaN NaN NaN NaN 2.67 1.87 2.56 1.88 2.39 NaN 2.77 2.83 NaN NaN NaN];
C = A;
for i=1:size(C, 1)
for j=2:size(C,2)-1
if isnan(C(i, j-1)) && isnan(C(i, j+1))
C(i, j) = NaN;
end
end
end
A, B, C
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!