Effacer les filtres
Effacer les filtres

Rescaling a variable with NaNs

5 vues (au cours des 30 derniers jours)
Peter P
Peter P le 25 Juil 2019
I want to rescale my matrix(56,53), it is filled with numbers from 1 to 7 and NaNs. I would like to change the 1 to 7, 2 to 6, 3 to 5 and 5 to 3, 6 to 2, and 7 to 1.
I found this solution https://stackoverflow.com/questions/48542055/reverse-coding-in-matlab but it does not work for me even though I replaced the NaNs with 0.
Any suggestions? Thank you in advance.

Réponse acceptée

Stephen23
Stephen23 le 25 Juil 2019
>> M = randi(7,3,5);
>> M(randi(numel(M),1,3)) = NaN
M =
6 7 7 6 4
3 NaN 5 NaN 6
5 4 NaN 2 7
>> Z = 8-M
Z =
2 1 1 2 4
5 NaN 3 NaN 2
3 4 NaN 6 1

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