How to replace -999 values with NaN in a Matlab table?

36 ビュー (過去 30 日間)
Leon
Leon 2020 年 10 月 13 日
コメント済み: Leon 2020 年 10 月 13 日
I have a Matlab table T1, with columns like the below:
T1.year
T1.month
T1.day
T1.var1
T1.var2
...
Some of its columns are numerical and some of them are strings. For the numerical columns, there could be some -999 values in some of the columns to indicate NaN values.
Is it possible to replace all of the -999 values with NaN values, without specifying each of the columns?
I wish I could do someting as simple as that?
T1(T1==-999) = NaN
Like I do in a column data.
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 10 月 13 日
Are you reading from a text file? If so then use 'TreatAsMissing', '-999' option when you do the readtable()
Leon
Leon 2020 年 10 月 13 日
Thanks for sharing that useful tip!
Unfortunately, I'm not reading from a text file. It is a carry-over Matlab table value.

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

採用された回答

Steven Lord
Steven Lord 2020 年 10 月 13 日
Use standardizeMissing.
t = array2table(magic(4));
t{2, 'Var3'} = -999
t2 = standardizeMissing(t, -999)
  1 件のコメント
Leon
Leon 2020 年 10 月 13 日
It works. Many thanks!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 10 月 13 日
T1 = convertvars(T1, @isnumeric, @no999);
function x = no999(x)
x(x==-999) = nan;
end
  1 件のコメント
Leon
Leon 2020 年 10 月 13 日
Many thanks! This one works equally well.

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

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by