How to convert a table into a structure
Mostrar comentarios más antiguos
Hi,
Lets say I have a table that looks like this:
Name = {'A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'}.';
Month = [1, 2, 3, 1, 2, 3, 1, 2, 3].';
Lat = [49, 50, 51, 52, 53, 54, 49, 50, 51].';
Lon = [-99, -100, -101, -102, -103, -104, -99, -100, -101,].';
A = [0.1, 0.2 , 0.3, 1.1, 0.9, 1.0, 0.1, 0.2 , 0.3,].';
T = table(Name, Month, Lat, Lon, A);
How would I convert this table into a 1 x 3 structure with the following shape ?
Name Month Lat Lon A
A 1x3 double 1x3 double 1x3 double 1x3 double
B 1x3 double 1x3 double 1x3 double 1x3 double
C 1x3 double 1x3 double 1x3 double 1x3 double
1 comentario
Blue
el 1 de Ag. de 2019
Respuesta aceptada
Más respuestas (1)
KSSV
el 1 de Ag. de 2019
Read about table2struct.
S = table2struct(T)
3 comentarios
madhan ravi
el 1 de Ag. de 2019
Note it produces a 9 X 1 strict array not 1 X 3 array.
KSSV
el 1 de Ag. de 2019
idx = strcmp(T.Name,'A') ;
S = table2struct(T(idx,:))
Blue
el 1 de Ag. de 2019
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!