All -9999 in a table to NaN

2 ビュー (過去 30 日間)
Huw Wadkin
Huw Wadkin 2021 年 8 月 27 日
コメント済み: Huw Wadkin 2021 年 8 月 27 日
Hi Everyone,
I have a table with results from a lot of sensors (1 column per sensor), if the results aren't valid then the output value is -5555.
I want to make all values of -5555 in the entire table =NaN, is there a quick way to do this?
I can do it for 1 column and create a loop to do it for all columns but is there an easier way?
Thanks in advance!

採用された回答

Steven Lord
Steven Lord 2021 年 8 月 27 日
Use standardizeMissing.
dblVar = [NaN;3;Inf;7;9];
cellstrVar = {'one';'three';'';'N/A';'nine'};
charVar = ['A';'C';'E';' ';'I'];
categoryVar = categorical({'red';'yellow';'blue';'violet';''});
A = table(dblVar,cellstrVar,charVar,categoryVar)
A = 5×4 table
dblVar cellstrVar charVar categoryVar ______ __________ _______ ___________ NaN {'one' } A red 3 {'three' } C yellow Inf {0×0 char} E blue 7 {'N/A' } violet 9 {'nine' } I <undefined>
B = standardizeMissing(A, 7)
B = 5×4 table
dblVar cellstrVar charVar categoryVar ______ __________ _______ ___________ NaN {'one' } A red 3 {'three' } C yellow Inf {0×0 char} E blue NaN {'N/A' } violet 9 {'nine' } I <undefined>
  1 件のコメント
Huw Wadkin
Huw Wadkin 2021 年 8 月 27 日
Thanks You! I knew I was missing something simple!

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

その他の回答 (1 件)

dpb
dpb 2021 年 8 月 27 日
isBad=(T{:,:)==-5555); % logical array across table T
T{:,:)(isBad)=nan; % assign NaN to those locations
Use your table variable name in place of T above, of course.
Depending on how you're creating the table, it may be easier/more direct to use the IsMissing indicator when create the table rather than have to fix up after the fact; we would have to know how the table is being populated to begin with to say -- that is, we need to see the code.

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by