Replacing <undefined> in categoricals or defining a default value

52 次查看(过去 30 天)
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.

采纳的回答

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

更多回答(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.

类别

Help CenterFile Exchange 中查找有关 Categorical Arrays 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by