How to save struct data from struct to excel?
Mostrar comentarios más antiguos
How can I save the output data of my matlab code in an excel file when the data are struct?
Respuesta aceptada
Más respuestas (1)
Raj Sodhi
el 29 de Sept. de 2019
In some cases you have a struct as an element of a struct. So I found it necessary to find only those an output those to the Excel file.
txt = fieldnames(strct) ;
sel = ones(size(txt)) ;
for i = 1:length(txt)
sel(i) = isstruct(strct.(txt{i})) ;
end
i_not_struct = find(~sel) ;
i_struct = find(sel) ;
x = [fieldnames(strct) struct2cell(strct)] ;
xlswrite(xlsfile ,x(i_not_struct,:),1,'a1') ; % winopen(xlsfile)
Then I treat the struct elements separately, as shown in the attached file.
Yours,
Raj
2 comentarios
Varun Vakayil
el 16 de Ag. de 2022
Thank you so much Raj. This was exactly what I was looking for.
Kip Risch-Andrews
el 9 de Nov. de 2022
This works perfectly for structures with many substructs, thanks for posting it!
Categorías
Más información sobre Spreadsheets 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!