Replace NaN with corresponding elements in another array.

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.

답변 (1개)

James Tursa
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

How can I replace the zeros in the resulting array with the corresponding elements in A?
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);

댓글을 달려면 로그인하십시오.

질문:

2015년 2월 2일

댓글:

2015년 2월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by