Assigning NaN to certain values

17 views (last 30 days)
IMC on 1 Mar 2021
Commented: IMC on 2 Mar 2021
I am trying to read nc file and it contains values (-177.6600, -177.6500, -177.6300, -177.5900, -177.5700). I want to assign NaN to all these values (there is a huge number of these values).I tried the following code but it didn't remove the maximum value i.e., -177.5700.
Temp = ncread('G\01.06.17\', 'Temperature');
Temp(Temp<=-177.5700)= NaN;
Kindly help.
Thank you.
IMC on 1 Mar 2021
Unfortunately, It didn't work.

Sign in to comment.

Accepted Answer

David Hill
David Hill on 1 Mar 2021
You might try rounding to 4 decimal places first
Temp(ismember(Temp,[-177.6600, -177.6500, -177.6300, -177.5900, -177.5700]))=nan;
  1 Comment
IMC on 1 Mar 2021
Thanks David!. It tried using your lines of code and it worked.

Sign in to comment.

More Answers (1)

Allen on 1 Mar 2021
A slightly more simple approach:
Temp(round(Temp,4)<=-177.57)= NaN;


Community Treasure Hunt

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

Start Hunting!

Translated by