Save dataset of struct with different kind of fields to Excel
2 views (last 30 days)
Show older comments
Hello,
I would like to save my Matlab data results, which is a 1 x 35 (35 participants) with 11 fields (11 outcome parameters) dataset.
I tried to use writetable(struct2table(DATA), 'DATA.xlsx') and it does save ALL the data, but is it not well organized anymore. It would be easiest to have all the parameters, which are fields with single values, doubles and structs, PER participant.
Moreover, writetable creates a kind of excelfile but I can not open it with Microsoft Excel, it only opens within Matlab, which is not useful for me. 

Any suggestion on how to save all this data per participant, instead of copy paste it...?
Thank you in advance.
2 Comments
Bob Thompson
on 28 Aug 2019
It seems like you have some visually complicated data structures. If you want to write them into an excel file you will need to determine how you want to take all of your arrays and structures and put them into 2D arrays with single elements per excel cell.
My best suggestion I can offer, until you know exactly how you want to expand the entire database, is to pick one collection of data (a single numeric array, or a single structure that doesn't contain other arrays) and decide how you want to present it. In my experience, a complex dataset usually needs to be handled piecemeal anyway, so learning how to deal with each small piece is not a wasted topic.
It is possible to automate the whole process, but because of the complexity of what you have shown in the image, and the visual simplicity of an excel sheet, it will be several small steps repeated, instead of a single command to dump the entire thing.
Answers (1)
Walter Roberson
on 28 Aug 2019
You cannot do that in Excel. Excel cells are scalars (or at most character vectors) and can never hold arrays or structs .
writetable() will replace all of the struct with empty entries, and will split all of those arrays into independent variables named after the linear index into the array.
Note: I had no difficulty openning the result of writetable() in Excel for Mac 2010.
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!