I want my NaN values of one matrix to transfer over to a second matrix. Help!

1 次查看(过去 30 天)
How would I go about doing this? For example I have two matrices of equivalent size:
[1 5 NaN 4 NaN 10 3]
[5 2 8 2 5 2 6]
I want my NaN values of the first matrix to replace the numbers in the second matrix, in the order in which they were located in the first matrix. My final result would look like:
[1 5 NaN 4 NaN 10 3]
[5 2 NaN 2 NaN 2 6],
where 8 and 5 of the second matrix were replaced by NaN.
Help please!

采纳的回答

Image Analyst
Image Analyst 2014-7-16
Try this:
a = [1 5 NaN 4 NaN 10 3]
b=[5 2 8 2 5 2 6]
b(isnan(a)) = nan
  1 个评论
alex
alex 2014-7-16
编辑:alex 2014-7-16
Perfect. Would you happen to know how to do this same process but for two different sized matrices, where I want to insert NaN in particular spots, with the number I'm "replacing" being shifted "down"? For example:
a = [1 5 NaN 4 NaN 10 3]
b = [6 1 0 3 5]
I want b to look like:
b = [6 1 NaN 0 NaN 3 5]
So essentially my NaNs are located in the same index as matrix 1, however, I want to preserve the numbers (not replace them like the first question) in b, by moving them down by one index in my new matrix.
Any tips?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by