Replacing <undefined> in categoricals or defining a default value

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.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2019년 12월 5일

답변:

2019년 12월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by