Replace NaN with corresponding elements in another array.
23 次查看(过去 30 天)
显示 更早的评论
I can find the locations of all the NaNs in an array, but how can I replace those elements with the corresponding elements of another array.
0 个评论
回答(1 个)
James Tursa
2015-2-2
A = original array with NaNs in it
B = array with desired replacement values
x = isnan(A);
A(x) = B(x);
2 个评论
James Tursa
2015-2-5
The zeros in what resulting array? If you have an array C the same size as A and you want to replace the zeros in C with the corresponding values from A, then use a similar technique as above. E.g.,
x = (C == 0);
C(x) = A(x);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!