"setdiff" operation getting reversed when using "categories" - Why??
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hanelore Pauna
am 8 Jan. 2020
Beantwortet: Walter Roberson
am 9 Jan. 2020
I have a table named "data" with one of the variables (categorical) being "Country". I am trying to merge all the categories that are not missing ("N/A") and after executing
land = setdiff(data.Country,"N/A")
in the workspace, "land" is a 9 x 1 categorical variable. This is perfect BUT when I execute
cats = categories(land)
"cats" becomes a 10 x 1 cell which includes the "N/A" that I got rid of using "setdiff" earlier.
WHY??
I want to use the "cats" in "mergecats(data.Country, cats, "Land")". Pls help.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 9 Jan. 2020
Each categorical array has two parts: a list of category names, and a list of "codes" (indices) of the current contents of the array.
Taking a subset of a categorical array does not change the categories that are allocated. For example,
A = categorical({'dog', 'human'});
[A(2), A(1)]
The A(1) and A(2) each extract a single element of the categorical array, but doing so does not create a new categorical array in which the respective values are the only possible categories. If it did create a new categorical array restricted to the one category, then [A(2), A(1)] would have to synthesize a new categorical array with new code numbers and category order 'human', 'dog', but that is not what happens: A(1) is a categorical object with a single code but with category names left intact.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Categorical Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!