MATLAB Answers

Replacing <undefined> in categoricals or defining a default value

4 ビュー (過去 30 日間)
Jannik Schneider
Jannik Schneider 2019 年 12 月 5 日
Answered: Steven Lord 2019 年 12 月 5 日
I have a table with serveral columns one ot them contains categorical values called parttype. Initially the column ist empty resulting in <undefined> in every cell. After user input some of the cells might get filled. Which leads to the situation in the picture below:
Capture.PNG
I now want to compare the the new table with the old one to find the rows that have been changed. But since compareing <undefined> with each other will always say they are different this is not an option.
Therfore I wanted to replace all <undefined> values with a value like '-empty-' or make this the default value. But I can't figure it out.

  0 件のコメント

サインイン to comment.

採用された回答

Walter Roberson
Walter Roberson 2019 年 12 月 5 日
YourTable.parttype = fillmissing(YourTable.parttype, 'constant', '-empty-');

  0 件のコメント

サインイン to comment.

More Answers (1)

Steven Lord
Steven Lord 2019 年 12 月 5 日
You could fillmissing to fill in the <undefined> entries, but if you want to leave them as missing data for future processing you could check that the elements in the two categorical arrays are equal or that they are both undefined/missing.
c = categorical(["C"; "A"; "B"; "C"; "A"; "C"; "C"], ["A"; "B"])
d = c;
d(3) = 'A';
d(4) = 'B';
d(7) = 'A';
d
c == d % Elements 2 and 5 match. Elements 1 and 6 are undefined in each array.
c == d | (isundefined(c) & isundefined(d)) % Elements 1, 2, 5, and 6 match.
c == d | (ismissing(c) & ismissing(d)) % Elements 1, 2, 5, and 6 match.

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

製品


リリース

R2018b

Translated by