
How do I convert all data from structures & substructures in a cell into a table?
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 7 Mai 2020
Réponse apportée : MathWorks Support Team
le 7 Mai 2020
I have a cell vector, in which each entry is a structure. Some of the fields in a structure is also a structure. For example:
Data{1,1}.a=1;
Data{1,1}.b='b';
Data{1,1}.K.x='x';
Data{1,1}.K.y='y';
Data{1,1}.K.z='z';is
Data{2,1}.a=10;
Data{2,1}.K.x='x';
Data{2,1}.K.v='v';
I want to convert the fields and data from structure into a table. For example, I would like to see:
T =
a b x y z v
---------------------------------
1 'b' 'x' 'y' 'z' ''
10 '' '' 'x' '' '' 'v'
Réponse acceptée
MathWorks Support Team
le 7 Mai 2020
Please download the attached file 'heteroStruct2table.m' and see the following example:
Data{1,1}.a=1;
Data{1,1}.b='b';
Data{1,1}.K.x='x';
Data{1,1}.K.y='y';
Data{1,1}.K.z='z';
Data{2,1}.a=10;
Data{2,1}.K.x='x';
Data{2,1}.K.v='v';
T = heteroStruct2table(Data,'K')

What the "heteroStruct2table.m" file does is to
1. add the missing fields in the original structs to make it become homogeneous
2. convert a cell array of homogeneous structs to table
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables 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!