フィルターのクリア

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

2 ビュー (過去 30 日間)
Jianne Pamintuan
Jianne Pamintuan 2022 年 12 月 1 日
コメント済み: Jianne Pamintuan 2022 年 12 月 1 日
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!

採用された回答

Matt J
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
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)
yourMatrix = 5×5
NaN NaN NaN NaN NaN 0.7783 0.3229 0.1825 NaN NaN 0.4769 0.0070 NaN NaN 0.8288 0.0583 NaN NaN NaN NaN NaN NaN NaN NaN 0.8891
A=yourMatrix;
A(isnan(A)) = 0
A = 5×5
0 0 0 0 0 0.7783 0.3229 0.1825 0 0 0.4769 0.0070 0 0 0.8288 0.0583 0 0 0 0 0 0 0 0 0.8891
B=yourMatrix;
B(isnan(B)) = []
B = 1×8
0.7783 0.4769 0.0583 0.3229 0.0070 0.1825 0.8288 0.8891
Jianne Pamintuan
Jianne Pamintuan 2022 年 12 月 1 日
I'll try them one more time.

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2022 年 12 月 1 日

Thomas
Thomas 2022 年 12 月 1 日
編集済み: Thomas 2022 年 12 月 1 日
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

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by