Rescaling a variable with NaNs
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Stephen23
on 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
0 Comments
More Answers (0)
See Also
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!