Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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!

Respuesta aceptada

Image Analyst
Image Analyst el 16 de Jul. de 2014
Try this:
a = [1 5 NaN 4 NaN 10 3]
b=[5 2 8 2 5 2 6]
b(isnan(a)) = nan
  1 comentario
alex
alex el 16 de Jul. de 2014
Editada: alex el 16 de Jul. de 2014
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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by