Export a structure into an excel file, with fieldnames as column headers.

Hi,
I have a structure with 61 fields, each field a 1x41 double, and I want to export this structure to an excel file where each field is its own collumn with the first row as fieldnames. I've tried converting to cell to use xlswrite, but this ends up being a nest cell and won't work. Any help would be appreciated. Thanks!

Answers (1)

Your struct contain data in row format. First convert it to column format before converting the struct to a table()
my_struct; % input struct
my_struct_new = structfun(@(x) x(:), my_struct, 'UniformOutput', 0);
T = struct2table(my_struct_new);
writetable(T, 'filename.xlsx')

Products

Release

R2020b

Asked:

on 1 Dec 2020

Answered:

on 1 Dec 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!