How to remove NaN from matrix / remove the dark blue pixels in the ocean
3 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1214388/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1214393/image.png)
Your help is greatly appreciated. Thank you!
0 个评论
采纳的回答
Matt J
2022-12-1
编辑:Matt J
2022-12-1
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 个评论
Matt J
2022-12-1
There's no way they both return the same output, as seen below:
a=rand(5)>0.5;
yourMatrix=rand(5).*(a./a)
A=yourMatrix;
A(isnan(A)) = 0
B=yourMatrix;
B(isnan(B)) = []
更多回答(2 个)
Walter Roberson
2022-12-1
I suggest you experiment with @John D'Errico FEX contribution https://www.mathworks.com/matlabcentral/fileexchange/4551-inpaint_nans
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!