How do I unstack/transpose table in Matlab?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MIKHAIL DEREVYANKO
le 31 Juil 2019
Commenté : stone_ward
le 21 Fév 2020
I need to unstack/transpose a table but couldn''t do using unstack ot transpose functions. Please see attached file.
2 commentaires
dpb
le 31 Juil 2019
So show us what you tried and what happened...showing an expected output would help I have no idea what you would want that to be.
Réponse acceptée
TADA
le 31 Juil 2019
unstack groups using a third column, but you can trick it to do what you want by adding a fake third column
id={'id1';'id1';'id2';'id2';'id2'};
cn={'c1';'c2';'c1';'c2';'c3'};
t=table(id,cn,cn,'VariableNames', {'id', 'cn', 'cn_'});
%unstack/transpose
t1=unstack(t,'cn_','cn');
t1 =
2×4 table
id c1 c2 c3
_____ ____ ____ ____
'id1' 'c1' 'c2' ''
'id2' 'c1' 'c2' 'c3'
4 commentaires
TADA
le 1 Août 2019
Modifié(e) : TADA
le 1 Août 2019
I don't know what the OPs use case really is, but sometimes a good visualization is all the processing you need.
I have to agree that in this case theres no reason to blame the documentation, we are tricking unstack to do something it wasn't exatly intended for
stone_ward
le 21 Fév 2020
How were you able to do this without defining an aggregation function? I've been trying to use unstack on my table of non-numeric data, which is similar to the example, except that I do happen to have 3 columns of data. Everytime I try to use it, I get an error about needing and aggregation function. When I supply one, I get the error "AGGREGATIONFUNCTION must return a value whose size conforms to elements of hte data variable 'Data'."
Note: Data is my datavar.
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!