Save structure in Excel

8 views (last 30 days)
Joanna Przeworska
Joanna Przeworska on 4 Mar 2021
Dear all,
I have a structure, which I want to save in Excel, in a way that each table is saved in different Excel sheet. Could you please help me with programming it?
dataset =
struct with fields:
Credit_broad: [205×48 table]
Credit_narrow: [205×48 table]
TotC_HH: [205×48 table]
TotC_NFC: [205×48 table]
GDP: [205×48 table]
...

Accepted Answer

Stephen23
Stephen23 on 4 Mar 2021
Edited: Stephen23 on 4 Mar 2021
F = fieldnames(dataset);
N = 'myfile.xlsx';
for k = 1:numel(F)
T = dataset.(F{k});
writetable(T, N, 'Sheet',F{k})
end
  1 Comment
Joanna Przeworska
Joanna Przeworska on 4 Mar 2021
It works as I expected. Thank you very much.
Kind regards,
JP

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!