could to create the categorical values for 2x2 cell array
Afficher commentaires plus anciens
I having cell array of 15x1. A (input training data for clustering)=15×1 cell array
{2×1 double}
{2×1 double}
{2×1 double}
{2×1 double}
{2×1 double}
{2×2 double}
{2×2 double}
{2×2 double}
{2×2 double}
{2×2 double}
{2×3 double}
{2×3 double}
{2×3 double}
{2×3 double}
{2×3 double}
B(targets for clustering) needs to be in the following manner.
[ 1
1
1
1
1
1 1
1 2
2 1
2 1
1 2
1 2 2
2 1 1
1 3 2
1 1 2
2 2 1]
Could you please help me to get it.
1 commentaire
Rik
le 23 Juin 2021
Feel free to reopen this question to edit it and make it more clear.
Réponses (1)
Walter Roberson
le 23 Juin 2021
B = cellfun(@convert_to_categorical, A, 'uniform', 0);
function C = convert_to_categorical(M)
if iscell(M)
C = cellfun(@convert_to_categorical, M, 'uniform', 0);
else
C = categorical(M);
end
end
6 commentaires
jaah navi
le 23 Juin 2021
Walter Roberson
le 23 Juin 2021
When you look at the data at B{12} compared to B{13} how can you tell whether the targets should be [2 1 1] or [1 3 2] ?
jaah navi
le 23 Juin 2021
Modifié(e) : Walter Roberson
le 23 Juin 2021
Walter Roberson
le 23 Juin 2021
Sorry, I still have no idea how the content of B{12} leads you to know to use [2 1 1] but the content of B{13} leads you to know to use [1 3 2] as the targets.
If you (somehow) knew you had
targ = { 1
1
1
1
1
[1 1]
[1 2]
[2 1]
[2 1]
[1 2]
[1 2 2]
[2 1 1]
[1 3 2]
[1 1 2]
[2 2 1]
}
and then you would
ctarg = cellfun(@categorical, targ, 'uniform', 0);
after which you would pass ctarg in as the target data.
jaah navi
le 23 Juin 2021
Modifié(e) : Walter Roberson
le 23 Juin 2021
jaah navi
le 23 Juin 2021
Catégories
En savoir plus sur Mathematics 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!