How to replace rows contain NaN with values from another matrix?

A = [728140.500000000 1840.00
728140.541666667 1780.00
728140.583333333 NaN
728140.625000000 NaN
728140.666666667 NaN
728140.708333333 NaN
728140.750000000 NaN
728140.791666667 NaN
728140.833333333 NaN
728140.875000000 NaN
728140.916666667 NaN
728140.958333333 NaN ]
B = [728140.500000000 1863.53
728140.541666667 1830.47
728140.583333333 1802.11
728140.625000000 1782.74
728140.666666667 1779.32
728140.708333333 1803.74
728140.750000000 1868.99
728140.791666667 1981.78
728140.833333333 2137.96
728140.875000000 2318.80
728140.916666667 2492.02
728140.958333333 2621.85 ]
Above is the Matrix A and B where first column of both matrix has the same value.. I need to replace the NaN from matrix A with the values from Matrix B. can anyone help this? should i use ismember function as well?

 採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 5 月 16 日

0 投票

A(isnan(A)) = B(isnan(A))

3 件のコメント

hanif hamden
hanif hamden 2019 年 5 月 16 日
thanks. one more i would like to remove all the value data at matrix A before replacing the NaN value with Matrix B.. Example.. before replacing NaN value at matrix A.. row 1 and row 2 need to be removed first..
Alex Mcaulley
Alex Mcaulley 2019 年 5 月 16 日
編集済み: Alex Mcaulley 2019 年 5 月 16 日
Do you mean this?
idx = ~isnan(A(:,2));
A(~idx,2) = B(~idx,2);
A(idx,:) = [];
hanif hamden
hanif hamden 2019 年 5 月 16 日
Thank you so much :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInterpolation of 2-D Selections in 3-D Grids についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by