Replacing <undefined> in categoricals or defining a default value

52 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

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

Più risposte (1)

Steven Lord
Steven Lord il 5 Dic 2019
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.

Categorie

Scopri di più su Categorical Arrays in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by