Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
alex
alex le 16 Juil 2014
Modifié(e) : alex le 16 Juil 2014
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!

Réponse acceptée

Image Analyst
Image Analyst le 16 Juil 2014
Try this:
a = [1 5 NaN 4 NaN 10 3]
b=[5 2 8 2 5 2 6]
b(isnan(a)) = nan
  1 commentaire
alex
alex le 16 Juil 2014
Modifié(e) : alex le 16 Juil 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?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by