Extracting Categories from array

9 vues (au cours des 30 derniers jours)
Angie Viviana Osorio Castellanos
Hello to everyone,
I am having a problem with the command "categories" for extracting the categories of an array that contains specific information. So the thing is that I have a table with a lot of information and I want to extract the categories that belong to one big category.
Here I leave the lines I wrote:
I have to load the information that I want to process:
datos = readtable(".xlsx");
%T is the table that saves the info for the big category
T(:,1) = find(datos.ZonaH == 1);%
It returns a 70x1 array. All is ok thill here.
This is the part where I have the problem
datos.tipologia is a categorical variable and I want to store the data that corresponds to the T above
tip(:,1) = datos.tipologia(T);
once I want to extract the categories of the variable "tip" the command extracts the whole table categories (a 93x1 array when the T size is 70x1) and I do not know why is this happenning sine I am trying to do so over the "tip" vaariable which is indexed in the fields that accomplish with my condition.
If someone has a clue I would be grateful.

Réponses (1)

Walter Roberson
Walter Roberson le 23 Juin 2022
As the Tips says,
  • C includes all categories in A, even if A does not contain any data from a category. To see the unique values in A, use unique(A).
That is, categorical() creates a datatype in which each element may be any of the categories associated with the datatype. categories() tells you the list of valid categories for the datatype. unique() will tell you the categories in-use .
For example, you might define a categorical {'Hearts', 'Clubs', 'Diamonds', 'Spades'} representing the suites that can be associated with a deck of cards. categories() would return that complete list -- the list of categories that elements of the variable are permitted to be. For any given "hand" of cards, you might be wanting to ask what categories are valid (see for example https://boardgamegeek.com/thread/775268/there-5-suit-deck-cards for a partial list of games with 5 or more suits possible.) But, yes, you might want to know which suits (categories) are actually present in the hand, and unique() will tell you that.

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by