Replacing <undefined> in categoricals or defining a default value
Afficher commentaires plus anciens
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:

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.
Réponse acceptée
Plus de réponses (1)
Steven Lord
le 5 Déc 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.
Catégories
En savoir plus sur Categorical Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!