How to remove NaN from matrix / remove the dark blue pixels in the ocean

2 views (last 30 days)
Hello everyone,
I have a rainfall plot and the dataset was acquired from APHRODITE. NaN values are located in the ocean regions/basins which is represented by dark blue pixels outside the administrative boundary in the image. Is there a way to completely remove them? Attached here are the plot itself and the matrix. I have tried 'isnan' and 'isinfinite' but none of them work.
Your help is greatly appreciated. Thank you!

Accepted Answer

Matt J
Matt J on 1 Dec 2022
Edited: Matt J on 1 Dec 2022
You can't remove the NaNs and keep the original rectangular shape of the matrix without replacing the NaNs with another value, e.g.,
yourMatrix(isnan(yourMatrix)) = 0;
If you don't care about keeping the original rectangular shape, you can just do,
yourMatrix(isnan(yourMatrix)) = [];
  3 Comments

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 1 Dec 2022

Thomas
Thomas on 1 Dec 2022
Edited: Thomas on 1 Dec 2022
Have you try "fillmissing" in newer MATLAB?
>> A = [nan 2 nan 4];
>> A(isnan(A)) = .5
A =
0.5000 2.0000 0.5000 4.0000
>> A = [nan 2 nan 4];
>> fillmissing(A, "constant", 0.4)
ans =
0.4000 2.0000 0.4000 4.0000

Community Treasure Hunt

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

Start Hunting!