Extract fields from struct and convert to excel file
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jonas Bender
el 10 de Oct. de 2022
Editada: Eric Delgado
el 14 de Oct. de 2022
Dear community,
I create a struct with numerous fields. I simply want to extract to fields (ISPC_together & GSI together) and export a .csv list.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1151345/image.jpeg)
Any suggestions? Thanks for your support.
Jonas
1 comentario
Dyuman Joshi
el 10 de Oct. de 2022
struct2table might be helpful (convert struct to table and save table as csv)
Respuesta aceptada
Eric Delgado
el 10 de Oct. de 2022
Try this...
data = struct('ISPC_together', 0.2053, 'GSI_together', 0.0172);
data(2) = struct('ISPC_together', 0.0243, 'GSI_together', 0.0040);
writetable(struct2table(data), 'data.csv')
2 comentarios
Eric Delgado
el 14 de Oct. de 2022
Editada: Eric Delgado
el 14 de Oct. de 2022
Are you trying to concatenate the data in one just table?! See below comments on your code and something that could help you...
sz = [2 2];
varTypes = {'struct', 'struct'};
% STRUCT as elements of your big table?!
varNames = {'ISPC_together', 'GSI_together'};
Table_ISPC_vs_GSI = table ('Size', sz, 'VariableNames', varNames, 'VariableTypes', varTypes);
for i = 1:numel (data)
% data(i).ISPC_together and data(i).GSI_togehter are DOUBLE, so you can't
% convert it to TABLE using STRUCT2TABLE.
Table_ISPC_vs_GSI(:,1) = {struct2table(data(i).ISPC_together)}
Table_ISPC_vs_GSI(:,2) = {struct2table(data(i).GSI_togehter)}
end
Try this...
dataSet1 = struct('ISPC_together', 0.2053, 'GSI_together', 0.0172);
dataSet1(2) = struct('ISPC_together', 0.0243, 'GSI_together', 0.0040);
dataSet2 = struct('ISPC_together', 0.1010, 'GSI_together', 0.1010);
dataSet2(2) = struct('ISPC_together', 0.2020, 'GSI_together', 0.2020);
[struct2table(dataSet1); struct2table(dataSet2)]
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!