Rescaling a variable with NaNs

5 Ansichten (letzte 30 Tage)
Peter P
Peter P am 25 Jul. 2019
Beantwortet: Stephen23 am 25 Jul. 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.

Akzeptierte Antwort

Stephen23
Stephen23 am 25 Jul. 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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by